in reply to correcting output
In addition to showing the code you're using to produce the output given in the OP, can you also please indicate how this code may relate to code discussed or implied in Removing Duplicates from a multiline entry and Only printing multiline entries once?
In Section
Seekers of Perl Wisdom