in reply to Perl code to format the text file by inserting tag in blank line
The sample data you give looks like a fragment of XML. If that is the case it is strongly advised that you use a suitable module (XML::Twig, XML::LibXML, ...) to do the heavy lifting for you.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
In Section
Seekers of Perl Wisdom