in reply to Cleaning up a script

You can use IO::File to create file handles that automatically close when they go out of scope. There's some info on this at perldoc -f open.