in reply to Regexp substitution using variables

You need to add the modifiers at the start of the substitution like this:

use strict; my $pattern = 'test'; my $replacement = 'New'; my $flags = 'i'; my $value = 'My Test Text'; $value =~ s/(?$flags)$pattern/$replacement/; print "$value\n";
This will print:
My New Test