my $allshows; for my $i ( 0 .. $#ids ) { $stmt = "SELECT id,title,teaser,number FROM shows WHERE id = '$ids[$i]'; &execute_it( $stmt ); #db operations to grab all matches push @$allshows, $sth->fetchall_arrayref({}); } $template = HTML::Template->new(filename => 'showslisting.tmpl'); $template -> param( showlist => $allshows );