my %hash; foreach my $row ( @array ) { my $k = defined($row->[1]) ? $row->[1] : 0; push @{ $hash{$k} }, $row->[0]; }