# @where_clause has been fully defined my $query = "SELECT * FROM $table WHERE "; $query .= join " AND ", @where_clause; my $sth->prepare( $query ) or die #stuff; $sth->execute( ) or die #stuff; #### # From your code above: if (defined($allocated_to) && $allocated_to ne '') { push @where_clause, "UPPER(ALLOCATED_TO) LIKE UPPER(?)"; push @entries, 'ALLOCATED_TO'; push @values, '\%$allocated_to\%'; } # # yada yada yada # my $query = "SELECT * FROM $table WHERE "; $query .= join " AND ", @where_clause; my $sth->prepare( $query ) or die #stuff; $sth->execute( @values ) or die #stuff;