in reply to Interpolating backreferences in an eval

'a$1$1c' is a template. You need a template module that understands that format. String::Interpolate should do the trick.
use String::Interpolate qw( ); sub expand { my ($rx, $from, $to) = @_; if ($from =~ $rx) { my $t = String::Interpolate->new(); $t->($to); $t->([ map substr($from, $-[$_], $+[$_] - $-[$_]), 1..$#- ]); print "$t\n"; } }

It's close to Perl code ('"a$1$1c"') so you could convert it to Perl code (the step you are missing) and execute it (eval $code), but that's a very bad approach.