#!/usr/bin/perl use strict; use warnings; my @input = ( "cocks are roosters!", "my cocks crow at dawn", "i'm a fan of the cocks", "game cocks all the way!", "do you like the gamecocks?" ); my $vulgar_list = { cocks => { regex => qr/(?{$word}->{regex}; if ($input =~ m/$regex/) { $foundvulgar = $word; last; } } print "phrase: $input found?: $foundvulgar\n"; $foundvulgar = ''; } __OUPUT__ phrase: cocks are roosters! found?: cocks phrase: my cocks crow at dawn found?: cocks phrase: i'm a fan of the cocks found?: phrase: game cocks all the way! found?: phrase: do you like the gamecocks? found?: