#!/usr/bin/perl use strict; use warnings; use Crypt::CBC; use feature 'state'; my $crypt = sub { state $c = Crypt::CBC->new( -key => 'foobar', -cipher => 'Blowfish', ); $_[0] = '' if !defined $_[0]; return $c->encrypt($_[0]); }; print $crypt->('foo')."\n"; print $crypt->('bar')."\n"; print $crypt->('')."\n"; print $crypt->()."\n";