use strict; use Mail::Internet; use Mail::Header; #variable declaration my $strSpamDir = 'D:/spam/SPAM_FINAL'; my $file; my $mail; opendir SPAM_DIR, $strSpamDir or die "could not opendir $strSpamDir:$!\n"; foreach $file (readdir SPAM_DIR){ if($file ne '.' && $file ne '..'){ open(MY_FILE, "$strSpamDir/$file") or die "could not open the file $strSpamDir/$file:$!\n"; $mail = Mail::Internet->new(\*MY_FILE); $mail->print_header(); close(MY_FILE) or die "could not close $strSpamDir/$file:$!\n"; } } closedir SPAM_DIR;