in reply to How to use \W in Regular Expression?
Is your question really about how to prevent $query="perl"; from matching anything in "This drink is fraperliscious!"?
$str =~ s/\b\Q$query\E\b/<em>$query<\/em>/ig;
or
$str =~ s/(?<!\w)\Q$query\E(?!\w)/<em>$query<\/em>/ig;
|
|---|