here's a little perl snippet you can use to get file header. I only tested on a exe file. you can follow the rest of what contrex has posted to get PE headers...may or may not work though.
use warnings;
my $file = "c:/someapplication.exe";
my $success = 0;
my $hex;
if (open(FH, $file)) {
binmode(FH);
my $bin;
sysread(FH,$bin,20);
close(FH);
$hex = uc(unpack("H*",$bin));
}
print $hex;