my $type = ref $first; ... croak("...") unless $type eq 'HASH' or (ref($first) and UNIVERSAL::isa($first, 'HASH')) #### use overload (); # added (), according to ysth's suggestion use Scalar::Util qw/blessed reftype/; use Carp; ## call this function as: can_deref_as($ref, $type) sub can_deref_as { my ($thing, $type) = @_; my %overload = ( HASH => '%{}', ARRAY => '@{}', SCALAR => '${}', GLOB => '*{}', CODE => '&{}' ); croak "Invalid reference type $type" unless $overload{$type}; return 0 unless ref $thing; return 1 if $type eq reftype $thing; return 1 if blessed $thing and overload::Method($thing, $overload{$type}); return 0; }