# open the file in raw/binary output for writing open MAILOUT, '>:raw', "$receiving/message-$thetime-$popcount.msg" or LogWrite("Unable to open message-$thetime-$popcount.msg for writing: $!"); # get the email into a temporary variable my $hold = $pop->HeadAndBody($popcount); # force it to use binary saving $hold =~ s/text\/plain/application\/x-msexcel/g; # write to file print MAILOUT $hold; # close the file close MAILOUT;