#fetch the rows into an array reference my %rethash; while (my @row = $sth->fetchrow_array){ # for a multicolumn query, the 1st column becomes the hash key push @{$rethash{shift(@row)}}, @row; }