It took me three or four minutes to figure out what your for loop does, and I still have no idea what it has to do with the stated problem. I think I would try a different approach altogether...
open INPUT, '<', 'inputfile';
open OUTPUT, '>', 'resultsfile';
local $/ = "</stanza>";
while (<INPUT>) {
my $stanza = $_;
if ($stanza =~ /<stanza/) {
my ($dottedquad) = $stanza
=~ /<stanza\s*(\d+[.]\d+[.]\d+[.]\d+)\s*>/;
$stanza .= " sl3 yet another line\n";
# Make other changes to $stanza here as desired.
print OUTPUT $stanza . $/;
}}