sub iff_ref { return ref $_[0] ? $_[0] : undef; } # Then your test becomes (if exists doesn't mind the notation) if (exists iff_ref($test[1])->[1]) {} # or it might have to be if (exists ${iff_ref($test[1])}[1]) {}