It sounds suspiciously like you trying to convert a text file from Project Gutenberg to HTML. Perhaps you should take a look at pg2html, a script written specifically to deal with that. http://www.abs.net/~donovan/pgdp.html
Comment on Re: Replacement and conversion of flat file text documents