in reply to if or die!

Only problem: It fills every file with the stinkin here document. over and over.

Yeah, it does. That's what your continue block does, if the conditional is true. That's what your else block does, if the conditional is not true. You need to stop commenting and uncommenting code and randomly adding and moving around code, because you're just making a mess and confusing yourself.

Here is your first problem:

} else { ($line =~ m/'syslogd'\)/); my $newline = $. + 3; $newline = $bgs; print OUT $newline; next; }</c>

This block only executes if the current line does not contain bgs. That's probably most lines of the file.

The regular expression does nothing. It's dead code. Delete it.

The next line declares the variable $newline and assigns it a value. This is nearly dead code, because the subsequent line overwrites that value with the heredoc, which gets printed in the next line. Control flow then skips to the continue block, which prints the current line.

You're not going to get this to work until you sit down, write out what you want to accomplish, list the necessary steps in order, and then translate that to code. Please do that; you'll save yourself a lot of time and trouble.