my $text = 'foo bar + \wbaz'; my $re = ' + \w'; if ($text =~ /(\Q$re\E)/) { print $1; } else { warn "nothing found\n"; }