#!/usr/bin/perl my $str = 'abc'; my $match = '(a)(.)'; my $repl = '$2$1'; $str =~ s/$match/"\"$repl\""/ee; print "$str\n"; # bac