my %hoa; while (<>) { chomp; my( $category, $item ) = split /\t/; push @{$hoa{$category}}, $item; } for my $cat ( sort keys %hoa ) { print "The following are in category $cat:\n"; for ( @{$hoa{$cat}} ) { print "\t$_\n"; } }