$sth = $dbh->prepare (qq{ SELECT f_user FROM `forbidden_usernames` }); $sth->execute(); while($row = $sth->fetchrow_hashref()) { if ($row->{f_user} =~ m/$str/i || $str =~ /$row->{f_user}/i) { return ("bad"); } }