# check each hypertext link within page
my @html = split(/a href=/, $html);
A recommendation: you are doing a lot of extra work to collect URLs and save the relative content, the code is a bit verbose and you could still miss something; peruse "standard" tools to help yourself:
- HTML::LinkExtor - Extract links from an HTML document
- LWP::UserAgent - Web user agent class - look at its get(...) method and in particular to its :content_file => $filename parameter
This should simplify things and help a lot