Pattern array
@patterns = ( qr/\bis\b/, qr/\ba\b/, qr/\bnone\b/, ); while (<>) { for ($loop_index = 0; $loop_index < $#patterns; $loop_index++) { if(/$patterns[$loop_index]/) { print "Matched pattern $loop_index!\n"; } else { print "Didn't match pattern $loop_index.\n"; } } }