use strict; use warnings; use Text::CSV_XS; my %hash; my $csv = Text::CSV_XS->new ({binary => 1, eol => "\n"}); open my $io, "<", "file.csv" or die "file.csv: $!"; my @fld = @{$csv->getline ($io)}; while (my $row = $csv->getline ($io)) { push @{$hash{$fld[$_]}}, $row->[$_] for 0 .. $#fld; } close $io;