use strict; use warnings; use Data::Dumper; my %outputs; while ( ) { my($day, $line, $output) = (split); $outputs{$line}{$day} = $output; } print Dumper(\%outputs); __END__ 2 CANNING 18353 2 MULTIPACK 14878 2 QUEST 911 3 CANNING 46775 3 MULTIPACK 42601 3 QUEST 1564 4 CANNING 81302 4 MULTIPACK 67542 4 QUEST 1879