in reply to Evaluate in a substitute

IO::String is useful for this kind of task.
use IO::String; ... $data =~ s/<# (\{.*?\}) #>/evalCap($1)/eg; sub evalCap { my $code = shift; my $str; my $str_fh = IO::String->new($str); my $old_fh = select $str_fh; eval $code; select $old_fh; $str; }
Update:
The regular expression can be simplified: s/<# {(.*?)} #>/....
As Abigail implies, the braces aren't needed in the eval. Nor in this case do they need to be escaped.

- nashdj