Here's the completed code that includes the "blank line check" -- the body is neither scanned for "Subject: **SPAM**" (saves time and prevents false positives) nor is the substitution string run against the body (so that any occurrences of "Subject: **SPAM**" are not touched in the body).
If someone feels like beautifying my Perl code, or optimizing the logic, I don't mind. ;-) Ville ------[begin excerpt from smtpprox MSDW/SMTP/Client.pm]------ sub yammer { my ($self, $fh) = (@_); my $spamheader = "X-Spam: yes\r\n"; my $spam = 0; local (*_); local ($/) = "\r\n"; while (<$fh>) { if ($_ =~ m/^Subject:\s*\*\*SPAM\*\*\s+/i) { $spam = 1; } if ($_ =~ m/^\s*$/) { last; } } seek( $fh, 0, 0); if ($spam == 1) { $self->{sock}->print($spamheader) or die "$0: write error: $!\n"; } while (<$fh>) { s/^\./../; if ($_ =~ m/^\s*$/) { $spam = 0; } if ($spam == 1) { s/^Subject:\s*\*\*SPAM\*\*\s+/Subject: /i; } $self->{sock}->print($_) or die "$0: write error: $!\n"; } $self->{sock}->print(".\r\n") or die "$0: write error: $!\n"; } ------[end excerpt from smtpprox MSDW/SMTP/Client.pm]------