in reply to Regexp::Common balanced curlies substitution

I tried to minimally change your prog, but I think it is also ugly yet. Unfortunately Regexp::Common::balanced always quotemeta its begin and end settings, so you cannot change behaviour right there.
... while ($text =~ m/$inpattern/xmsg) { my $first = substr $1, 1, -1; my $second = substr $2, 1, -1; $outpattern =~ s/\$1/$first/xmsg; $outpattern =~ s/\$2/$second/xmsg; } $text =~ s/$inpattern/$outpattern/gee; ...