my %cats; # .. loop to get a row # @row contains the retrieved row push $cats{ $row[1] }, $row[0]; # "Hash of arrays structure" # End of loop to get a row #### for my $c (sort keys %cats){ my $values = $cats{ $c }; print "$c\t", join (" ", @$values), "\n"; } #### my $ItemsPerLine=3; for my $c (sort keys %cats){ my $values = $cats{ $c }; print "$c\t"; for my $i(0..$#$values){ $i % $ItemsPerLine==0 and print "\n\t"; print $values->[$i], " "; } print "\n" unless $#$values % $ItemsPerLine==0; }