in reply to How to apply modifiers to a substitution via variable?

You can do the second part without an eval but with an ee modifier, like this

$ perl -le ' > $str = q{aaabbbaaa}; > $repl = q{$1}; > $str =~ s{a+(b+)a+}{$repl}ee; > print $str;' bbb $

The first e executes the $repl resulting in $1, the second e executes the $1 resulting in whatever was captured, "bbb" here.

Cheers,

JohnGG