my $j = 0; for (my $i = 0; $i <= $#array; ++$i) { $current = $array[$i]; if($current == undef) { push @empty, $j++; } } print "undefined indices: @empty \n";