in reply to Why do we need to close filehandles?

One technique that can help manage the time a file is open is to use lexical file handles:

... { open my $fileIn, '<', $filename or die "Failed to open $filename: +$!\n"; ... }

The end of the enclosing block (the '}') is the place where the lexical file handle ('$fileIn') goes out of scope and is closed if it hasn't been closed already.

True laziness is hard work