Help for this page
$to =~ s/\$(\d+)/$a[$1-1]/g;
$to =~ s/\\(.)|\${(\d+)})|\$(\d+)/ (defined $1 ... ) ) /eg;