For certain flags you can do:
$value =~ s/(?$flags:$pattern)/$replacement/; [download]
In reply to Re: Regexp substitution using variables by jwkrahn in thread Regexp substitution using variables by MikeTaylor