in reply to Too much recursion
It looks like you are reading some kind of configuration file. I would suggest using a primitive state machine, something like:
my $host; while (<$fh>) { if (/^hostname/) { $host = new_host( $_ ); next; }; if ($host) { add_to_host( $host, $_ ); }; }; sub new_host { ... }; # return id of new host section sub add_to_host { ... }; # do whatever is needed
I don't know what the file format is, and what the code really should do, so I can't say what's in the two last subs. At least there's no recursion, and you can process as many hostnames as you want.
In Section
Seekers of Perl Wisdom