Aside from your lack of 'strict' and 'warnings', and out-dated function-calling style, the real problem is that input from STDIN has a newline at the end of it, and you need to remove it.
chomp($dir = <STDIN>)
Jeff japhy Pinyan,
P.L., P.M., P.O.D, X.S.:
Perl,
regex,
and perlhacker How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart