# Takes a statement handle, and returns the entire result # set as a reference to an array of hashes. sub fetchall_arrayref_hash { my $sth = shift; my @rows; while (defined(my $row = $sth->fetchrow_hashref())) { push @rows, $row; } return \@rows; } # Then elsewhere $template->param(table1 => fetchall_arrayref_hash($sth));