my @rows= (); # an array reference while (my $row= $sth->fetchrow_hashref) { push (@rows, $row); } #you can then pass the array of hash refs straight to an #HTML template loop construct or iterate over the array as #below foreach my $str (@$rows) { print $str->{'id'}; }