I think that compress will read from a pipe (on Solaris, it does, though I don't know about elsewhere...). That having been said, you could do something like this:
open(OUT,"|compress > outfile.Z") or die "Couldn't open pipe to compre
+ss: $!";
print OUT "stuff\n"