my %foods; while () { chomp; my( $category, $item ) = split /\t/; push @{$foods{$category}} ,$item; } for my $category ( keys %foods ) { print "$category : \n"; for my $item ( @{$foods{$category}} ) { print "\t$item\n"; } print "\n"; }