my $repl = '"foo$1bar"'; $a = '12345'; $a =~ s/(23)/$repl/ee; print $a,"\n"; $ ./perl /tmp/p 1foo23bar45 $