in reply to Insert lines into specific stanza line

Just detect the closing stanza tag, then add lines before it:
use strict; use warnings; while (<DATA>) { print "extra line\n" if m{</stanza>}; print; } __DATA__ <stanza 12.34.56.78> sl1 this is my line sl2 justanotherline </stanza>

prints out:

<stanza 12.34.56.78> sl1 this is my line sl2 justanotherline extra line </stanza>