use warnings; use strict; use File::Basename qw/basename/; use Data::Dumper; $Data::Dumper::Useqq=1; my $zipfile = "$ENV{HOME}/file.zip"; my $subject = 'logs'; my $recipient = 'haukex@localhost'; my @emailcmd = ('/usr/bin/mailx','-s',$subject,'--',$recipient); print Data::Dumper->Dump( # Debug [ $zipfile,$subject,$recipient,\@emailcmd], [qw/ zipfile subject recipient *emailcmd/] ); open my $ifh, '<:raw', $zipfile or die "$zipfile: $!"; open my $ofh, '|-', @emailcmd or die "@emailcmd: $!"; printf $ofh "begin %03o %s\n", ((stat($zipfile))[2] & 0666)||0644, basename($zipfile); my $buf; print $ofh pack 'u', $buf while read $ifh, $buf, 45; print $ofh "`\n", "end\n"; close $ofh or die $! ? $! : $?; close $ifh;