in reply to Re: how can i hold temporary values in a recursive function
in thread how can i hold temporary values in a recursive function

#2 leaks memory every time you call rec_helper. The sub you create references $recursive which references the sub, so you have a memory cycle. The simplest solution is to avoid using a lexical to hold the reference to the sub. It even simplifies the code a little.
sub rec_helper { my %state; local *recursive = sub { my( $arg ) = shift; ... if( ( $arg = $state{ $arg ) ) == ... ) { return recursive( $arg ); } else { return 0; } }; }