a(40); sub a { print calldepth(),$/; if ($_[0] > 0) { a($_[0]-1); } } sub calldepth { my $i = 0; while( @a = caller($i++) ) { } return $i - 1; }