SELECT ID, sentence FROM texts WHERE sentence LIKE '% $query %' #### SELECT ID, sentence FROM texts WHERE sentence LIKE '% $query %' OR sentence LIKE '$query %' OR sentence LIKE '% $query' OR sentence = '$query' #### SELECT ID, sentence FROM texts WHERE sentence LIKE '%$query%' #### my $sth = $dbh->prepare(<<'EOSQL'); SELECT ID, sentence FROM texts WHERE sentence LIKE ? ESCAPE ? EOSQL $sth->execute("%$query%", '\\'); my $results = []; while (my @row = $sth->fetchrow_array) { push @$results, \@row if $row[1] =~ /\b\Q$query\E\b/; }