#!perl -w #use strict; #use warnings; use HTML::Parser; my @links; my $string = qq~Hallo das ist ein Titellinktext1 Ein anderer Text linktext2 text~; my $p = HTML::Parser->new(); $p->handler(start => \&start_handler,"tagname,attr,self"); $p->parse($string); sub start_handler{ return if(shift eq 'ccc'); #print my $tagname = shift; my ($class) = shift->{class}; my $self = shift; if($class eq 'title') { $self->handler(text => \&get_title, "dtext"); } elsif($class eq 'a') { $self->handler(text => \&get_a, "dtext"); } else { $self->handler(end => sub{ },"dtext"); } #$self->handler(end => sub{push(@tests,[$class,$text]) if($tagname eq 'title')},"tagname"); } sub get_title() { my ($test ) = @_; print $test; } sub get_a() { #$self->handler(end => sub{push(@links,[$class,$text]) if($tagname eq 'a')},"tagname"); #foreach my $link(@links){ # print "Linktext: ",$link->[1],"\tURL: ",$link->[0],"\n"; #} }