You use 'inflate', whereas I believe the gzip man page mentions 'deflate' for the compression mode. Did I misunderstand? I suspect compress/deflate is analogous to making a balloon smaller by deflating it.

Assuming you want to send out content in gzip'ed form and the images are static, you may want to place them in a separate directory, serve them from a lightweight process (thttpd, nginx, or a lean apache) or behind a proxy server (squid, varnish, pound, whichever you prefer). Granted, that's a non-programming solution which may not fit your case.

For storing gzip'ed data, I suppose IO::Compress::Gzip would allow you to gzip() to store to a scalar reference.

Yeah, you are right... sorry. Your analogy makes sense now.
Basically my perl script is the entire HTTP server, so it handles accessing the filesystem and caching.
So I guess using your example I can have the contents of the image in variable $foo.
Then do: