As stated above, that should just work, but if you're supplying the file name on the command line be aware that (on unix at least) the shell will also interpret wildcards before your code will ever see them. In other words; make sure $file contains exactly what you think it contains.