First, may I suggest to annotate your code with comments, and to streamline it a bit, because I found it quite incomprehesible. For instance, if I look at

s/[\\|<]$//g; s/^[\\|<]//g; s/<//g;
You first delete all \, | and < from the end and the beginning of $_, and then you erase all < from the whole $_. If you erase all < from $_ anyway, you don't need to do this too for the special cases 'begin' and 'end'. Also, if you want to erase completely certain characters from a string, tr is better readible, so your code would become
s/[\\|]$//g; s/^[\\|]//g; tr/</d;
Also I find your question self-contradictory. You ask
But for {LEAD} it doesnot creates the proper tag. ... For {LEAD} it creates the tag

So first you say it does not create the tag, then you say it does create the tag. The problem rather seems to me that it does not create an opening tag for HEADLINE only, or is there still something not correct with LEAD?

You should put into your code various print statements, so that you see what is going on, in particular after your program has encountered HEADLINE for the first time. I would do the same if I had to debug such a program...
-- 
Ronald Fischer <ynnor@mm.st>

In reply to Re^5: Delete till end of line to another string by rovf
in thread Delete till end of line to another string by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.