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