#! perl use strict; use warnings; my %names; while () { my ($first, $last) = split; push @{$names{$first}}, $last if $last; } my $name_to_find = 'John'; print "$name_to_find --> ", join(', ', @{$names{$name_to_find}}), "\n"; __DATA__ John Marry John Lea John Paul David Patrik David Sam