... my $replace = '"To {$1}"'; $text =~ s/$pattern/$replace/gee; # eval twice