my @headerlines; while () { last if /^\r?\n/; push @headerlines, $_; } my $msg = Mail::MboxParser::Mail->new(\@headerlines, "");