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

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

I have a 15,000 line text file where I want to "reverse" groups of lines. In the example below, a group is a Title followed by 0 or more lines of text. What is an efficient approach to do this?

Input file:
Title 1 Line of text A Line of text B Title 2 Line of text C Title 3 Title 4 Line of text D
Desired Output:
Title 4 Line of text D Title 3 Line of text D Title 3 Title 2 Line of text C Title 1 Line of text A Line of text B
Thanks, Dave