if (defined($x) && eval { @$x || 1 }) { print "\$x can be used as an array ref (@$x)\n"; } else { print "\$x cannot be used as an array ref\n"; }