if (defined(fileno($fh))) { print "Filehandle!\n"; } else { print "Not a filehandle\n"; }