in reply to Perl regex

[ The OP silently updated his question. This post is now obsolete. ]

Result:

foreach(loop through each $word in search phrase) { $answer =~ s{\Q$word\E}{<b><u>$word</u></b>}g; }

Read perlop for details.