use strict; use warnings; use IO::Handle; open my $fh, '>', 'file' or die $!; test_fh($fh); close $fh or die $!; test_fh($fh); sub test_fh { my ($fh) = @_; if ($fh->opened()) { print "fh is opened and ready\n"; } else { print "fh is closed\n"; } return; }