It was a little hard to find, but this may be what you want:
perlretut Says:A modifier available specifically to search and replace is the s///e evaluation modifier. s///e treats the replacement text as Perl code, rather than a double-quoted string. The value that the code returns is substituted for the matched substring. s///e is useful if you need to do a bit of computation in the process of replacing text. This example counts character frequencies in a line:
In reply to Re: Interpolate into replacement with s//?
by SuicideJunkie
in thread Interpolate into replacement with s//?
by philkime
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |