c:\@Work\Perl\monks>perl -wMstrict -le "my $user_input = 'ab+c'; my $excluded = qr{ \A \Q$user_input\E _ABC_ .* [.] pdf \z }xms; ;; FILE: foreach my $file (qw( ab+c_ABC_something.pdf ab+c_ABC_anything.pdf ab+c_ABC_.pdf xab+c_ABC_.pdf ab+c_ABC_.pdfx xab+c_ABC_.pdfx abc_ABC_something.pdf abc_ABC_anything.pdf abc_ABC_.pdf abc _.pdf xyzabc_ABC_hipdip foobar )) { next FILE if $file =~ $excluded; print qq{'$file' is not excluded}; } " 'xab+c_ABC_.pdf' is not excluded 'ab+c_ABC_.pdfx' is not excluded 'xab+c_ABC_.pdfx' is not excluded 'abc_ABC_something.pdf' is not excluded 'abc_ABC_anything.pdf' is not excluded 'abc_ABC_.pdf' is not excluded 'abc' is not excluded '_.pdf' is not excluded 'xyzabc_ABC_hipdip' is not excluded 'foobar' is not excluded