my %combined; open(my $input, "<", "flatfile.dat") or die ("Unable to open file"); my $line = <$input>; chomp ( $line ); my @headers = split("|", $line); while (<$input>) { chomp; my @row = split("|"); for my $header (@headers) { push( @{ $combined{$header} }, shift(@row) ); } }