in reply to Capturing in interactive replace?

You need to use a string eval, and make sure to escape the dollar-sign on "$mystring":
$string1 = 'sometext(.*)something(.*)'; $string2 = '$1:$2'; $mystring = "sometext--blahblah--something--foobar--"; eval "\$mystring =~ s/$string1/$string2/"; print "$mystring\n";
That is: $string1 and $string2 will be interpolated before being passed to eval, and $mystring will not be interpolated. In the example above, eval will see:
$mystring =~ s/sometext(.*)something(.*)/$1:$2/;
and that is what will be executed within the eval.

Replies are listed 'Best First'.
Re^2: Capturing in interactive replace?
by zylot (Initiate) on Feb 20, 2008 at 23:56 UTC
    Thank you, that does really help!

    Thanks
    Zilot