in reply to Help with formatting a text file

take a look at perlform, especially the @* and ^* formats and the "Using Fill Mode" section.

however, it may be profitable to investigate the text manipulation modules mentioned in a previous response.