my $path =~ /^\Q$str\E # the base string; '\tmp\foo', e.g. (\\.*)? # optionally match a slash, etc. $ # match end of string /x;