my @restricted_words = qw ( funk shucks crud ); my $restricted_re = '(?:' . join('|', @restricted_words) . ')'; $restricted_re = qr/$restricted_re/; if ($word =~ $restricted_re) { print "wash your mouth out!\n"; } else { print "Such a nice boy\n"; }