my $newpath='C:\Perl\bin'; .... if ($path->[0] =~ /$newpath/ ) # perl sees this as ... =~/C:\Perl\bin/; # you need either to $newpath = quotmeta $newpath # or do it in the match =~/\Q$newpath/