# Do your prepare() and execute() up here ... $sth->bind_columns( \my( $id, $option, $data) ); my %stuff; while ($sth->fetch) { push @{$stuff{$id}}, { option => $option, option_data => $data, }; }