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