Here is one solution:
$string =~ s/$regex/eval "\"$replace\""/e;
The problem with your method was that to get that to work it would have to do variable substitution twice, first to substitute $replace with '$2 $1', then a second variable substitution of $2 and $1. Using eval in connection with the e modifier basically does just this second variable substitution.
In reply to Re: regular expression problem
by jethro
in thread regular expression problem
by perl_fan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |