in reply to Parse C-like define statements

This is certainly not an easy problem. It's easy to write a piece of code that will only terminate because it has exhausted all memory, or ran out of stack space - because you can have loops. Furthermore, even if there aren't loops, a naive approach might lead to a program that runs in time quadratic to the number of defines.

I suggest approaching the problem as seeing the file as a graph. Each #define is a node, with as (outgoing) edges edges to nodes its definition is refering to.

Now that you have made a graph, first you need to find out whether there are any loops - if there are, determine what you are going to do with them. Throw them out, die(), whatever. Second, do a topological sort, then you can process the defines like you are doing now:

$defines{$_} =~ s/<(\w+)>/$defines{$1}/g;

Luckely, there's a graph module on CPAN that could help you.

Abigail