__DATA__ CUSTA 1/2015 100 12/2015 1,000 CUSTB 2/2015 100 3/2015 100 #### $VAR1 = { 'CUSTA' => [ undef, '100', undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, '1,000' ], 'CUSTB' => [ undef, undef, '100', '100' ] }; #### # note: # # @{ ... } turns the hash entry for this customer into an array. # # map creates a new list consisting of one element, undef, for each # element from the list it is given, i.e. @months #### #!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Sortkeys = 1; my @months = qw/dummy jan feb mar apr may jun jul aug sep oct nov dec/; my %report; my $cust; while () { chomp; if ( /^[A-Z]/ ) { $cust = $_; @{ $report{ $cust } } = map { undef } @months; next; } my ($date, $value) = split ' ', $_; my ($mon, $year) = split '/', $date; $report{$cust}[$mon] = $value; } print Dumper(\%report); __DATA__ CUSTA 1/2015 100 12/2015 1,000 CUSTB 2/2015 100 3/2015 100 #### $VAR1 = { 'CUSTA' => [ undef, '100', undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, '1,000' ], 'CUSTB' => [ undef, undef, '100', '100', undef, undef, undef, undef, undef, undef, undef, undef, undef ] };