Perl Regexp interpolating

interpolation, perl, regex

Solution

$a = 'abcdef';
$b = '"f$1d"';
$a =~ s/d(e)f/$b/gee;
print $a;

Notice that there are two `e` modifiers in `/gee`; the second one evaluates `"f$1d"` string to `fed`.

As a side note you don't need `/g` as you're replacing only one pattern occurrence.

Problem

I have some code: ``` $a = 'abcdef'; $b = 'f\1d'; $a =~ s/d(e)f/$b/g; print $a; ``` I get `abcf\1d`, but how can I get `abcfed`?

Original source