Try using
Compress::Zlib . Once compressed, you'll probably want to base64 encode them. This will increase the size of your zip by 4/3, but will allow you to store 'binary' data on the cookie.
use Compress::Zlib ;
use Storable ;
my %hash = &some_data ;
my $data = pack( "u*",
Compress::Zlib::MemGzip( freeze \%hash) ) ;
# now you can do as you please with $data
# to unthaw:
my $hashref = thaw( Compress::Zlib::MemGunzip(
unpack( "u", $data ) ) ) ;
You'll also want to carefully manage the variables you need stored, as cookies tend to allow a minimal amount of space.
Update: GrandFather is absolutely right, though. The best way to store the data is on the server. This method will work, if you're insistent.
Another Update: I've been thinking about this, and I strongly advise you not to do it.
If you give a variable to a user, that user may choose to unpack, unzip, and thaw it. Then that user could look at your data structure and do something to the cookie ( for example, set $data{'user'} = 'admin' ) and send it back to you. This could be disastrous.
Peace monks,