open INPUT, '<', 'inputfile'; open OUTPUT, '>', 'resultsfile'; local $/ = ""; while () { my $stanza = $_; if ($stanza =~ //; $stanza .= " sl3 yet another line\n"; # Make other changes to $stanza here as desired. print OUTPUT $stanza . $/; }}