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