use Scalar::Util 'reftype'; my $reftype = reftype $x; if ( !defined $reftype ) { print "\$x is not a reference.\n"; } elsif ( $reftype eq 'HASH' ) { # do something with %$x } elsif ( $reftype eq 'ARRAY' ) { # do something with @$x } elsif ( $reftype eq 'SCALAR' ) { # do something with $$x } else { # do something else } # ...