use HTML::TokeParser; my $count = 0; my $parsee = HTML::TokeParser->new('test.html') or die "couldn't open test.html: $!"; while (my $tag = $parsee->get_tag('a')) { $count++ if $tag->[1]{href} =~ m{(http|ftp)://}i; } print "There are $count links in this file.\n";