my $buf; use MIME::Base64 qw(encode_base64); open(FILE, "$attachfile") or die "$!"; binmode(FILE); while (){ $buf .=$_; } $buf = encode_base64($buf); $smtp->datasend($buf);