in reply to Includes within includes

First, let me add my votes to those above of merlyn and throop. Recusion is all you need and threads will only complicate the code and confuse those reading it. For example, you've got a "sleep 2;" in your code. If that is there to be "nice" and let other code run. A threaded version might run faster just because it's diluting the effect of the sleep, not because it's any more efficient. If it's there because a delay is needed, you will have to think about this need in the context of multiple threads running simultaneously. You may even have two threads trying to create the same directory at the same time, if the include branches overlap. (You may want to check if the directory exists, before you make it, even in the recursive case.)

Looking at your code, one big problem stands out with regard to recursion. "FH1" needs to be localized in some way (as you'll see in merlyn's article). I think most people today would do this by putting the file handle in a scaler variable. Just put a

my $fh1;
at the top of your srch_include() sub, and replace "FH1" with "$fh1". That should take care of the problem. There are other ways to take care of this. You can localize a file handle with a simple "local *FH1;", but it's an old way of doing things. You can also accomplish what you need just by closing the file handle so that it can be reused. You can use "IO::File" as mentioned in merlyn's article. For me "my $fh1;" is the best of the choices.