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