$ perl -wE' for my $re (qw/ foo bar /) { my $string = "test foo"; $string =~ s/$re/replaced/o; say $string; }' test replaced test replaced