Like others I cannot reproduce that error message with that line of code. You can get that error message from an open statement however. Most likely you have read all or part of a filename ($dir?) from a file or <STDIN> and forgotten to remove the trailing "\n" using chomp.