#! /usr/bin/perl use strict; use warnings; my $string = qq~
links
text1
~; my $content = new Parse($string); my $foo = $content->content("bla"); print $foo . "\n"; package Parse; use vars '$self'; use base 'HTML::Parser'; sub new { my $class = shift; $self = { }; $self->{html} = shift; bless $self, $class; return $self; } sub content { my $self = shift; my $name = $self->{name} = shift; my $p = HTML::Parser->new(); $p->handler(start => \&start_handler,"attr,self"); $p->parse($string); return $self->{content}; } sub start_handler{ my $tmp = shift; my $class = $tmp->{id} || $tmp->{name}; my $html = shift; my ($return, $text); if($class eq $self->{name}) { $html->handler(text => sub{$text = shift;},"dtext"); $html->handler(end => sub{ $self->{content} = $text},"attr"); } }