{ open my $fh, '<', $filename or die $! while ( <$fh> ) { # do your stuff. } # Note, your $fh is about to pass out of scope, which # will close the filehandle in cleanup. } { $open my $fh, '<', $filename or die $! while ( <$fh> ) { # do your other stuff. } } # Now the second filehandle fell out of scope and closed too.