use strict; my $patt1 = '!!'; my $patt2 = '++'; my $string = 'hello!!there++everyone!!in the web'; if ( $string =~ m{$patt1} ) { print "Matches patt1\n"; } if ( $string =~ m{\Q $patt2 \E}x ) { print "Matches patt2 with /x\n"; } if ( $string =~ m{\Q$patt2\E} ) { print "Matches patt2\n"; }