use strict; use warnings; while () { print "Matched: $_" if /^(?!help).*?train times (?!to\b|from\b)\w/; } __DATA__ help train times from xyz load train times including xyz help train times including xyz book train times at 1234