in reply to How can I change substitution options within a program?

$source = "abc"; $find = "a"; $replace = "x"; $opt = "g"; eval "\$source =~ s/$find/$replace/$opt"; print $source;

Replies are listed 'Best First'.
Re^2: How do I change substitution options within a program?
by ikegami (Patriarch) on Nov 01, 2006 at 17:09 UTC

    Better:

    eval "\$source =~ s/\$find/\$replace/$opt";

    Even better:

    $opt =~ /[^imsx]/ and die(...); eval "\$source =~ s/\$find/\$replace/$opt";