This is not exactly what I want, and I've already looked at these things. I am not looking to compress all the output in response to the request from the browser. I am looking to have my CGI give output as either 'gzipped' or as 'text' depending on an option selected by the user. If selected, I want the output to come as an file attachment.
Look a little harder, CGI::Compress::Gzip works with mod_perl:
Note that the Zlib library on which this code is ultimately based requires a fileno for the output filehandle. Where the output filehandle is faked (i.e. in mod_perl), we instead use in-memory compression. This is more wasteful of RAM, but it is the only solution I've found (and it is one shared by the Apache::* compression modules).