http://www.perlmonks.org?node_id=687035


in reply to Regular expression "replace string interpolation" problem

This should work:
... my $replace = '"$1 Perl"'; $text2 =~ s/$match/$replace/ee;
Or you might want to write it like this:
my $replace = '$1 Perl'; # use original setting of $replace $text2 =~ s/$match/'"'.$replace.'"'/ee;
Probably even a better solution would be write $replace as a subroutine:
my $replace = sub { "$1 Perl" }; $text2 =~ s/$match/$replace->()/e;
and then only level of evaluation is needed.