@structure = ( { ... }, [ { ... }, { ... }, ], [ { ... }, { ... }, ], [ { ... }, { ... }, ], ); #### my @structure = ( $hashref_from_first ); foreach @query { ... push @structure, [] foreach @subquery { ... push @structure->[0], $hashref; } }