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