#!/usr/bin/perl use 5.010; use strict; use warnings; use Crypt::CBC; my $crypt = sub { my $val = shift; state %CB; my $cb = \%CB; if (!defined $cb->{cipher}) { say "Debug: erzeuge Objekt"; $cb->{cipher} = Crypt::CBC->new( -key => 'foobar', -cipher => 'Blowfish', ); } if (defined $val) { return $cb->{cipher}->encrypt($val); } }; say $crypt->('foo'); say $crypt->('bar');