{ package fakehash; use overload "%{}" => sub { return {1 => 2} }; sub new {my $c; bless \$c}; } use strict; use warnings; use Scalar::Util qw( reftype ); my $fake = fakehash->new; printf "fake is ref %s\n", ref $fake; printf "fake is reftype %s\n", reftype $fake; # Try to use $fake as a hashref. # The return value of eval should be 1 if the first # statement is successful, as 1 is the last statement executed # in the block # The assignment to (undef) is to avoid this warning: # "Useless use of a variable in void context" if ( eval {(undef) = %$fake; 1}) { print "fake is pretending to be a hashref\n"; }