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


in reply to Keeping the first occurence of a pattern, and removing the other occurences

Use a look-behind assertion to delete all occurrences that don't follow a store name heading.

s/(?<!===\n)DEPT:\s+PRODUCE\n+/\n/g;

Of course, I am assuming the input has UNIX-style line endings (newline character only). If not, you may need to replace "\n" with "\r\n" where appropriate.