This doesn't excuse not telling us what $dir contains (or even rule it out), but it seems the error is coming from Perl code, not from the shell. That's most curious, and I'm wondering about a false positive. But since you didn't provide us the code that issues the error, can't tell.