#!/usr/bin/env perl use strict; use warnings; use Data::Dump; my %hash; while () { chomp; my ($value, $key) = split /\t/; push @{$hash{$key}}, $value; } dd \%hash; __DATA__ Obi Wan Jedi Yoda Jedi Count Dooku Sith #### { Jedi => ["Obi Wan", "Yoda"], Sith => ["Count Dooku"] } #### #!/usr/bin/env perl use strict; use warnings; use Text::CSV; use Data::Dump; my %hash; my $csv = Text::CSV::->new({sep_char => "\t"}); while (my $row = $csv->getline(\*DATA)) { push @{$hash{$row->[1]}}, $row->[0]; } dd \%hash; __DATA__ Obi Wan Jedi Yoda Jedi Count Dooku Sith #### { Jedi => ["Obi Wan", "Yoda"], Sith => ["Count Dooku"] }