my $replace = sub { "$1 Perl" }; $text2 =~ s/$match/$replace->()/e;