use warnings;
it will warn you of things like OUT only being used once in the script. You also need to get into the habit of checking the success/failure of the system calls:
close(OUT) or die "Can't close OUT: $!";
or:
close(OUT) or warn "Can't close OUT: $!";
same when you open() files or do any number of things.
my %hash = ();
open($hash{'filehandle1'}, '>', 'test.txt') ¦¦ die $!;
print {$hash{'filehandle1'}} ("hello");
for my $key (keys %hash)
{
close($hash{$key}); # all filehandles are closed now
}
but of course, you should keep track of your filehandles anyhow, this is just a workaround.