This won't work:
my $pattern = q/(...)(...)/;
my $replace = q/$2-$1/;
s/$pattern/$replace/g;
because the
$replace is inserted into the "double-quoted" string on the right side, and not again rescanned to see if it has any variables to be replaced. So you get a literal
$1 and so on.
However, if you trust your invoker, you could try something like:
my $pattern = q/(...)(...)/;
my $replace = q/$2-$1/;
s/$pattern/qq{$replace}/eeg;
as long as the curly braces balance nicely.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.