Are you sure this will be valid HTML? You may try to write a regexp for this (at least I don't know how can it be archieved using HTML::Entity/HTML::TreeBuilder), like this:
$ cat t1.pl #!/usr/bin/perl -p BEGIN{$i=0} s|<p>((?<!</p>).*)</p>|'<bpt i="'.++$i.'" x="'.$i.'"><p></bpt>'.$1.'<e +pt i="'.$i.'"></p></ept>'|egs; $ seq 1 10 | while read; do echo '<p>text<xczcx>texxxxx</p>'; done | p +erl t1.pl <bpt i="1" x="1"><p></bpt>text<xczcx>texxxxx<ept i="1"></p></ept> <bpt i="2" x="2"><p></bpt>text<xczcx>texxxxx<ept i="2"></p></ept> <bpt i="3" x="3"><p></bpt>text<xczcx>texxxxx<ept i="3"></p></ept> <bpt i="4" x="4"><p></bpt>text<xczcx>texxxxx<ept i="4"></p></ept> <bpt i="5" x="5"><p></bpt>text<xczcx>texxxxx<ept i="5"></p></ept> <bpt i="6" x="6"><p></bpt>text<xczcx>texxxxx<ept i="6"></p></ept> <bpt i="7" x="7"><p></bpt>text<xczcx>texxxxx<ept i="7"></p></ept> <bpt i="8" x="8"><p></bpt>text<xczcx>texxxxx<ept i="8"></p></ept> <bpt i="9" x="9"><p></bpt>text<xczcx>texxxxx<ept i="9"></p></ept> <bpt i="10" x="10"><p></bpt>text<xczcx>texxxxx<ept i="10"></p></ept> $
but this is wrong way (for example, it will break on nested <p>...<p>...</p>...</p> tags). Why do you need such a strange tag combination?
Sorry if my advice was wrong.

In reply to Re: Adding counters for text replacement by aitap
in thread Adding counters for text replacement by bartelby

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.