#!perl use strict; while (){ # capture word with () # [- ] character is space or dash if (m/(design|otherword)[- ]controlled/i){ # captured word is in $1 print "Word < $1 >found in $_"; } else { print "No word found in $_"; } } __DATA__ This is a design controlled string This is a design-controlled string This is a controlled design string This is an otherword-controlled string