A negative look ahead assertion at the start of the line (not a look back) is what you want:
use strict; use warnings; while (<DATA>) { 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
Prints:
Matched: load train times including xyz Matched: book train times at 1234
In reply to Re^3: negate pattern match
by GrandFather
in thread negate pattern match
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |