The code you have shown should not have the glob problem. I suspect that in another version of this code, you used $filename when you meant $file. Your choice of names for these variables is very misleading. $file contains the name of the file. $filename contains a file handle (Strictly, a reference to a file handle). Perl does not care what names you choose to use, but more descriptive names would help you prevent this kind of error.