my @values; my @fields = qw( title date ...); # what fields do you want? $sth=$dbh->prepare("SELECT " . join(',' @fields) . " FROM Videos WHERE $FieldsN LIKE ?") or die DBI->errstr; $sth->execute( $SearchCrit ) or die DBI->errstr; while( my @vidinfo = $sth->fetchrow_array() ) { my %hash; # there's probably a better way to join these arrays, # but this is the easiest to understand OTTOMH ... # basically mapping the output to the respective field # name for ( my $i = 0; $i < @fields ; $i++ ) { $hash{ $fields[ $i ] } = $vidinfo[ $i ]; } push @values, \%hash; # push a reference to the hash onto the array } $tmpl->param( stuff = \@values );