sub routine1 { my($arg1,$arg2) = @_; ... return $result; } #### { my %cached_results; sub routine1 { my($arg1,$arg2) = @_; return $cached_results{"$arg1||$arg2"} if(defined $cached_results{"$arg1||$arg2"}); ... $cached_results{"$arg1||$arg2"} = $result; return $result; } sub clear_cache1 { %cached_results = (); } }