for my $c (sort keys %cats){ my $values = $cats{ $c }; print "$c\t", join (" ", @$values), "\n"; }