# this function is not recursive; it is called once # and returns with the subroutine calls it /would have/ # made had it be implicitly recursive sub get_sub (param1,...,paramN) # shift params, which are are assumed to data stucts refs initialize @retsubs = () if terminating condition FALSE # create/modify params used in recursive call initialize new _param1 to some value; ... initialize _paramN to some value; loop to get set of next subs for next level of recursion push "sub {return get_sub(_param1,...,paramN);})" onto @retsubs; end loop endif return {substack=>@retsubs,retval1=>'somevalue'}; end get_sub # initialize call stack with first set of subs to call my @callstack = array of subs returned by get_sub(param1,...,paramN); # now execute the call stack until it's been exhausted while(@callstack) { pop next $sub off of @callstack; execute sub ref, $x = $sub->(); push subs returned by get_sub(param1,...,paramN) onto @callstack; end while