I guess the detour is intentional? You dereference $msg into an array, concatenate the array into a string $rfc2822, then split it into an array again, just to pass the array reference to Mail::Internet. In particular, you remove all newline characters from your message along the way.
At least the following works fine:
Code:
foreach my $msgnum (keys %$msgnums) {
my $obj = Mail::Internet->new( $pop->get($msgnum) );
my $old_body = $obj->body;
$out = "@$old_body";
$out =~ s/\n/<br>/gmi;
print $out."<br><br>************************************************************<br><br>\n";
}
It seems like yours doesn't work for the following reason: Have a look at $rfc2822, each line except the very first begins with whitespace. I guess that the lines returned by $pop->get($msgnum) end in "\n ", i.e. newline followed by a space character. So if your string is split at newlines later, those space characters will be shifted to the next line, but then Mail::Internet doesn't recognize the next header.
It also works if you use "split /\n /, $rfc2822", but who knows if the messages returned by Net::POP3 will always look like that? I wonder if this is a bug somewhere.