Chris is certainly correct, but some explanation is needed. Editing multi-line files is a bit tricky. Finding perl's documentation of this flag is challenging and the result disappointing ("m Treat string as multiple lines." Refer: perldoc perlop). The book "Perl Best Practices" has a detailed explanation of this issue. The meat of it is that /m changes the meaning of the meta-characters ^ and $ to refer to the start/end of a line rather than the start/end of the string. (The book recommends always using the flags /xms) Good Luck, Bill

Hmmm, granted, the /m flag will not do any harm here, but I do not see how it will be useful here. So far, except perhaps for a post title which might be misunderstood, there is nothing in this post to tell us that we have a multiline string at hand.

In post 29, I tried to explain why Chris's fix works. I consider perl's documentation of this issue very poor. I guess that I did not do any better, Sorry about that.

The update in my later post is the key part of your code with Chris's fix added. It is a complete program that anyone can run to prove that the fix works. It does not introduce any new ideas. Good Luck, Bill