my @words = split /\s+/,$keyword; my @list; my $where = join(' OR ', map { my $col = $_; map { push @list, "%$_%"; "$col like ?" } @words } qw(mfg productID desc) ); my $sth = $dbh->prepare('SELECT * FROM productTable WHERE ' . $where); $sth->execute(@list);