# takes one argument, the filename to encode # returns one value, the filename of the temporary(!) output file use File::Temp qw/tempfile/; sub uuencode { my ($infile) = @_; my ($tfh,$tfn) = tempfile(UNLINK=>1); open my $fh, '<:raw', $infile or die "$infile: $!"; printf $tfh "begin %03o %s\n", ((stat($infile))[2] & 0666)||0644, $infile; my $buf; print $tfh pack 'u', $buf while read $fh, $buf, 45; print $tfh "`\n", "end\n"; close $fh; close $tfh; return $tfn; }