use IO::Compress::Deflate qw(:all); use IO::Uncompress::Inflate qw(:all); sub put { my $handle = shift ; my $string = shift; print $handle pack("V", length $string) , $string ; } sub get { my $handle = shift ; my $buf ; read($handle, $buf, 4) == 4 or return undef ; my $len = unpack("V", $buf); read($handle, $buf, $len); return $buf; } my $outBuffer ; my $out = new IO::Compress::Deflate \$outBuffer; put($out, "hello world"); put($out, "goodbye"); $out->close ; my $in = new IO::Uncompress::Inflate \$outBuffer; my $got ; while (defined ($got = get($in))) { print "$got\n" ; }