use strict; use warnings; my $arrayref; foreach (@$arrayref) { } print($arrayref\n"); # ARRAY(0x1abefc0) #### use strict; use warnings; my $arrayref = getArrayref(); # this sometimes returned undef # Manually vivify it. $arrayref ||= []; if (@$arrayref) { ... } #### use strict; use warnings; my $arrayref = getArrayref(); # this sometimes returned undef if ($arrayref && @$arrayref) { ... }