sub html_tree { defined(my $self = shift) or die "no self"; defined(my $html = shift) or die "no html content"; return HTML::TreeBuilder->new_from_content($html) or die "couldn't put html content into tree"; } #....... #get the right bestellung link, which then redirects. if ( my $bestellung_link = $html_tree->look_down("_tag"=>"img","src"=>"images/but_zur_detailseite.gif")->parent() ) { if ( $bestellung_link->tag eq "a" && $bestellung_link->attr("href") && ( my $target_url = $bestellung_link->attr("href") ) ) { #do stuff... } }