use Modern::Perl; use Data::Dumper; my %rep; map {my @x = split; push @{ $rep{ $x[0] } }, $x[1]} grep /\S/, ; say Dumper \%rep; __DATA__ a b c d a d c a f g f h