in reply to Re: How to do regex backreferences within $variable replacement text?
in thread How to do regex backreferences within $variable replacement text?

When allowing the emdedding of code (loosely defined), provide an escape mechanism!!! For example,

When adding your escape mechanism, careful not to break existing functionality. For example,

Update: A solution is to replace

$to =~ s/\$(\d+)/$a[$1-1]/g;

with

$to =~ s/\\(.)|\${(\d+)})|\$(\d+)/ (defined $1 ? $1 : (defined $2 ? $a[$2-1] : $a[$3-1] ) ) /eg;