#!perl use DBI; use strict; my $dbh = get_dbh(); # connect to db # build regex my @keyword = qw(www http .com); my $words = join '|',@keyword; my $regexp = qr/$words/i; print "Regular Expression is $regexp\n"; # search for key words my $sql = 'SELECT comment_ID,comment_content FROM wp_comments'; my $sth = $dbh->prepare($sql); $sth->execute(); my @spam = (); while (my ($id,$content) = $sth->fetchrow_array()) { if ($content =~ /$regexp/ ){ print "ID : $id\ncomment : $content\n\n"; push @spam,$id; } } # delete records my $sql_del = 'DELETE FROM wp_comments WHERE comment_ID = ?'; my $sth_del = $dbh->prepare($sql_del); for my $id (@spam){ # enable this when you are sure it's working !! #$sth->execute($id); print "Deleted $id\n"; }