in reply to Calculating subtotals from a table

my $data; my $years = qr{^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)}; my %map = ( 2, 2001, 3, 2002, 4, 2003, 5, 2004 ); while( <DATA> ){ /$years/ or next; $data->{country}{$1} = [ $2, $3, $4, $5 ]; $data->{years}{$map{$_}} += ${$_} for 2..5; } __DATA__ COUNTY 2001 2002 2003 2004 ------ ------ ------ ------ ------ 26005 432 505 547 555 26021 910 984 1026 1077 26023 225 282 272 299 #If print Dumper($data); $VAR1 = { 'country' => { '26149' => [ '355', '415', '346', '367' ], ..... 'years' => { '2004' => '5734', '2002' => '5327', '2001' => '4663', '2003' => '5503' } };