use Smart::Comments; sub foo ($) { my $arg = shift; state %cache; return $cache{$arg} if exists $cache{$arg}; my $result = ... something costly ...; ### Look MA! No hands! Really... $cache{$arg} = $result; }