You may find
Getting size of call stack relevant. Basically, the argument to
caller is how many frames down on the stack to return. You'll need to start at 0 and increment the argument until you exceed the current stack depth, at which point
caller will return
undef in scalar context. There's no simple way (that I know of) to just get the depth explicitly.