in reply to $1 not getting applied to reg ex
How do you know that the regex has matched? If $dir doesn't end in a slash, the match will fail and will not set $1.
the lowliest monk