my @list; for my $a (@a) { for my $b (@b) { push(@list, $h{$a}{$b}); } } # return @list;