my $allokay = 1; my $idx = 0; while($idx < 5 and $allokay) { $allokay &&= $line =~ /$TEXTS[$idx++]/; } if($allokay) { foreach $text (@TEXTS) { $line=~ s/$text/$text<\/b>/g; } }