in reply to search and replace from array values

You can build a regex with the @search array, and substitute in the @replace value via a hash lookup.
my $s = "I have red stuff, blue stuff, orange stuff, and more red stuf +f."; my @search = ("red", "orange", "blue"); my @replace = ("yellow", "black", "green"); my %replacements; @replacements{ @search } = @replace; # use a hash slice to populate + the search=>replace pairs. my $re = join '|', @search; $s =~ s/\b($re)\b/$replacements{$1}/g; print $s;