my %hash = map { $x => $y } grep { my $y = $list[$x]; $y ne $undef; [$x, $y] } for(my $x = 0; $x <= $#list; $x++);