That's the solution I would use myself. I'd just like to make a note that FILE type filehandles are global. Instead of globals you should use a lexical filehandle: open my $file, '<', $filename or die $!. See perldoc -f my and perldoc perlsub (Private Variables via my()) for an explanation of globals and lexicals.