use strict; use warnings; open(OUT, ">test.txt") or die "Can't open file to write, $!."; if(defined fileno *OUT){ print "File handle is valid."; }else{ print "Nope."; } close OUT;