It should not match
lion because regex is by default case sensitive... Are you sure you didn't type
Lion?
You can make the regex case insensitive by adding the
i modifier -- as it stands now, your pattern would match
Tiger but not
tiger or any other variation in case.
As a minor side note,
\b will match things you may not want in front of a word, such as punctuation (e.g. ?tiger?), so it'd probably be preferable to use something more specific like
(?:^|\s) instead:
Also, why not place lion and tiger in a group (non-capturing if you prefer), and put the
(?:^|\s) and
\b outside the group?
%count = $regex($1-,/(?:^|\s)(?:lion|tiger)\b/gi)