eval{-d $handle}; if($@ =~ /dirfd function is unimplemented/) { # then you know $handle is a dirhandle } elsif($@) { die $@; # a different problem } else { # it's safe to call -X on $handle }