my $modifiers = 'i'; my $text = 'abc'; my $pattern = 'BC'; if ( $text =~ m/(?$modifiers:$pattern)/) { print "it matches\n"; }