$sql_stmt = "select * from database where 1=1"; #This is how I would do the match in Postgresql #Check your DB docs for the correct syntax my $matchstring = join ' OR ', map { "PlantDescription ~ ".$dbh->quote($_)} @keywords; $sql_stmt .= ' AND '.$matchstring if $matchstring;