http://qs321.pair.com?node_id=11119662


in reply to Tricky regex problem

Not a single regex but one way to do what you want is to read your file in paragraph mode, with $/ and split the logic:

{ local $/ = ""; # Edit: added use of local for good practice while (<DATA>) { s/^##.*//s unless /^\w/m; print; } } __DATA__ ## Remove ## Keep this ## Remove ## Also keep that

Otherwise you could use a negative look ahead assertion (?!^\w)

Edit: seems like I really didn't read the requirement well enough ^^"