use IO::Handle; # or IO::File *IO::Handle::DESTROY { print "here\n" } { open my $fh, '<', 'a-file' or die; }