my %g = (k => [8, 2, 10, 2, 1, 3],l => [10, 7, 9, 0, 1]); %gkey = sort keys %g; print 0+@{$g{each %gkey}}, "\n";