my $hash_ref; while ( my $row = $sth->fetchrow_hashref ) { push @{ $hash_ref->{ $row->{ 'msgid' } } }, { 'option' => $row->{ 'option' }, 'option_data' => $row->{ 'option_data' } }; } #### my $rows = $sth->fetchall_arrayref; my %hash = map { $_->[0] => { 'option' => $_->[1], 'option_data' => $_->[2] }; } @{$rows}; #### '1234' => [ { 'option_data' => 'fooval', 'option' => 'foo' }, { 'option_data' => 'quuxval', 'option' => 'quux' } ], '1235' => [ { 'option_data' => 'barval', 'option' => 'bar' } ], '1236' => [ { 'option_data' => 'bazval', 'option' => 'baz' } ]