in reply to
extract the function call chains of specific length
A few years ago, I had to deal with a very similar project ... except that the system to be analyzed consisted of a Devil’s Brew of SAS files, Korn shell scripts, and Tivoli Workload Scheduler (TWS) scripts. (Don’t ask ... it worked, and they paid, but ick ... and I forevermore shall do worshipful obesiance at the altar of Parse::RecDescent.)
One of the (key, as it turns out ...) ideas that I used was to write one set of scripts to extract the information individually from every script that might be processed. These are individual, single links. I stored everything in an SQLite database file. (Once I grokked the initially-painful lesson that you must use Transactions, SQLite did everything that I could have wished-for.) Any of the data-extraction scripts could be run or re-run at any time. All of the chain-building or other scripts worked entirely by issuing queries against this database as their source of information. They did not use recursion at all, but did create some fairly elaborate data structures.