$a =~ /\Q$b\E/ $a =~ /\Q$b/ # \E is optional my $b_re = quotemeta($b); # This is what \Q does $a =~ /$b_re/