use strict; use warnings; my %sets; while( ) { chomp; next unless length; my( $entry, $color ) = split /\s+/; push @{$sets{$entry}}, $color; } foreach my $entry ( keys %sets ) { print $entry; foreach my $color ( @{$sets{$entry}} ) { print "\t$color\n"; } } __DATA__ John red Mike yellow Peter white Peter brown Jim purple Antony orange Antony green George black