in reply to Removing Headers from E-mail Messages.

My first thought was to suggest Email:Simple, from which you could do something like:

my $mail = Email::Simple->new($msg); my (%headers_i_care_about); foreach my $i_care_about (qw(Received Date From To Subject Return-Path)) { my @{$headers_i_care_about{$i_care_about}} = $mail->header($i_care_about); # or, if you want it as a single string, something like: # my $headers_i_care_about{$i_care_about} = # join(' ', $mail->header($i_care_about)); }

If that fails to work as you desire, then what you could fall back to is to look at the message line-by-line until you find the first completely blank line (which indicates the end of the headers, if memory serves), remembering the last line that did not begin with whitespace, and concatenating the current line with the previous one if it did, possibly on the order of:

my (%headers); my ($lastheader); foreach my $line (@msg) { last if ($line =~ m/^\s*$/); # Reached end of headers if ($line =~ m/^\s+(.+)/) { $headers{$lastheader} .= $1; } else { my @parts = split(/:/, $line, 2); $headers{$parts[0]} = $parts[1]; $lastheader = $parts[0]; } }

Hope that helps.