for(my $x = 0; $x <= $#array; $x++) { next unless $array[$x]; # do stuff with $x and $array[$x] } #### my %hash = map { $x => $y } grep { my $y = $list[$x]; $y ne $undef; [$x, $y] } for(my $x = 0; $x <= $#list; $x++); #### $list{100} = 'dog'; $list{435} = 'cat'; $list{1040} = 'tax form'; while(($index, $element) = each %list) { # do stuff with $index and $element }