my $replace = '$1 Perl'; # use original setting of $replace $text2 =~ s/$match/'"'.$replace.'"'/ee;