in reply to pattern matching question

Because your backslash is being interpreted by the regex. Try
if($_ =~ /^(\Q$match_dir\E)/

Caution: Contents may have been coded under pressure.