in reply to $variable as regex in s///

As philcrow says, this works for me too.

But I wanted to point out something else ...

Is there a good reason that you're using the "evaluate" flag? (the e of ge)  Because, if not, you may just have wanted:

$string =~ s/$regex/'bar'/g; # This will print ... "this is a 'bar'" # but with "/ge" .... "this is a bar"

It took me a moment to figure out why the output didn't contain apostrophes!


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/