my %hash = (); for(my $x = 0; $x <= $#sparse_list; $x++) { my $y = $spase_list[$x]; next if $y eq undef; $hash{$x} = $y; }