It's hard to read your code (please use <code></code> tags), but it might be easier to just use WWW::Mechanize ... note especially it's methods for getting links.
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get($url);
print $mech->content;
my @links = $mech->all_links();
my @someLinks = $mech->find_all_links( ... );