my $data = {}; use Text::CSV; my $csv = Text::CSV->new(); open FILE, "foo.txt"; # open a file my $line = ; # get the header line $line =~ s/^#//; # strip off leading # $csv->parse($line); # parse line ... my @cols = $csv->fields(); # ... storing column names while(my $line = ){ # loop through rest of file $csv->parse($line); # parse line ... my @vals = $csv->fields(); # ... getting the values # my %row = map { $cols[$_] => $vals[$_] } 0 .. $#cols; # and hashing up based on col names # $data->{ $row{ $cols[0] } } = \%row; # stick this hash into big data structure. # NOTE: it's hashing on the first column.. # might want to change if necessary # UPDATE: just use a hash slice: @{ $data->{ $row{ $cols[0] } } }{ @cols } = @vals; } close FILE; # close file -- all done!