Here the sample code for extracting the header part from the mail.
Code:
use strict;
use warnings;
use Data::Dumper;

use Mail::Header;
my $messagefile = "mail"; #here the mail is a file which contains s data as this is for testing
open(MESSAGE,"$messagefile") or
die "Unable to open $messagefile:$!\n";
my $header = new Mail::Header \*MESSAGE;
print Dumper \$header;
close(MESSAGE);
The output will be as follows
Code:
$VAR1 = \bless( {
                   'mail_hdr_foldlen' => 79,
                   'mail_hdr_modify' => 0,
                   'mail_hdr_list' => [],
                   'mail_hdr_hash' => {},
                   'mail_hdr_mail_from' => 'KEEP',
                   'mail_hdr_lengths' => {}
                 }, 'Mail::Header' );