use strict; my $re = qr/foo./; my $str = "foo bar baz"; $str =~ s/$re/FOOD /; print "$str\n"; __output__ FOOD bar baz