in reply to Exec'ing a regex stored in a scalar variable

You need to distinguish between the search pattern and the replace string. To store the compiled search regex, use

$search = qr/pattern/;
and to use it in a substitution command, just plug it in:

s/$search/replace/g;
To store the entire substitution, I'd go with a subref:

my $rep = sub { $_[0] =~ s/a/b/g }; my $string = "abc"; $rep->($string); print "$string\n";