What I always used to do 

my $data = {};
my $sth = $dbh->prepare(
    'SELECT name, colour, shape FROM thing WHERE smell=?'
);
$sth->execute('bad');
while ( my $row = $sth->fetchrow_hashref ) {
    $data->{$row->{colour}}{$row->{shape}} = $row;
}