@structure = ( [{ ... }, ], [ { ... }, { ... }, ], [ { ... }, { ... }, ], [ { ... }, { ... }, ], ); ## foreach @query { my @ex = executeRequest ($_); push @structure, []; for (my $i=0;$i<=$#ex;$i++) { push @structure->[$i], $ex[$i]; } #### my @structure = ( [ # Result from first query. { 'field1_statement1' => 'value', 'field2_statement1' => 'value' }, ], [ #Results from second query { 'field1_statement2' => 'value', 'field2_statement2' => 'value', 'field3_statement2' => 'value' }, { 'field1_statement2' => 'value', 'field2_statement2' => 'value', 'field3_statement2' => 'value' } ], [ # results from third query { 'field1_statement2' => 'value' } ] ); my $q2Total = sum @{ $structure[ 1 ] }; print $q2Total."\n";