my $items_sth = $dbh->prepare('SELECT * FROM Items'); my $actions_sth = $dbh->prepare('SELECT * FROM Actions WHERE item_key = ?'); my @items; $items_sth->execute($item_row->{item_key}); while (my $item_row = $items_sth->fetch_hashref()) { my $item = { item_key => $item_row->{item_key}, item_description => $item_row->{item_description}, item_summary => $item_row->{item_summary}, actions => [], }; my $actions = $item->{actions}; $actions_sth->execute($item_row->{item_key}); while (my $action_row = $actions_sth->fetch_hashref()) { push @$actions, { key => $action_row->{action_key}, summary => $action_row->{action_summary}, }; } push @items, $item; }