in reply to filehandle cleanup

I also believe that if your file handles are of the type
open my $in, "$filename" or die "$filename";
it will automatically close when you leave the scope of the variable $in.
just thought I would offer that up as well.