http://www.perlmonks.org?node_id=11101201

cmic has asked for the wisdom of the Perl Monks concerning the following question:

Was trying to pring only lines *not* begining with TAGS, but this snippet doesn't works. And I don't know why.. Thans for any explanation.
# # Negative lookbehind , huh ?? # while (<DATA>) { if (/(?<!TAGS)(.*?)(?=TAG2)/xgi ) { print "Negative lookbehind: "; print $1, "\n"; } } # __DATA__ TAG1 text one TAG2 TAG1 text two TAG2 TAG1 text three TAG2 TAGS text four TAG2 TAG1 text five TAGT TAG1 text six TAG2

This code prints:
Negative lookbehind: TAG1 text one
Negative lookbehind: TAG1 text two
Negative lookbehind: TAG1 text three
Negative lookbehind: TAGS text four
Negative lookbehind: TAG1 text six

-- cmic. Life helps. Perl Too.