chomp for @blocked; for my $m (@blocked) { if ($FORM{'comments'} =~ /\b$m\b/) { # print your message here. exit; # could also last outside the loop } }