You can use pipes | to send a program output to (another) program input.
For example to send an attach with sendmail via CGI, without using a temporary file to mimencode the attach, you can pipe the output from cat to the input of mimencode:
#code from a sub
unless (open(MAIL, "| $sendmail ")) {
return 0
};
my $attach=$q->param('upfile');
my $path = $q->tmpFileName($attach);
open (ATTACH,"cat $path | mimencode |") or return 0;
[cut]
close ATTACH;
close MAIL;