for(my $x = 0; $x <= $#array; $x++) { next unless $array[$x]; # do stuff with $x and $array[$x] }