use HTML::Parser; { package MyParser; use base 'HTML::Parser'; sub start { my($self, $tagname, $attr, $attrseq, $origtext) = @_; if ( $tagname eq 'div' and $attr->{class} eq 'text12' ) { push @{$self->{text12}}, ''; # start a new text 12 collection $self->{in_text12} = 1; } else { $self->{text12}->[-1] .= $origtext if $self->{in_text12}; } } sub end { my($self, $tagname, $origtext) = @_; $self->{in_text12} = 0 if $tagname = 'div'; $self->{text12}->[-1] .= $origtext if $self->{in_text12}; } sub text { my($self, $origtext, $is_cdata) = @_; $self->{text12}->[-1] .= $origtext if $self->{in_text12}; } } my $p = MyParser->new; $p->parse_file(*DATA); print "Got: $_\n\n" for @{$p->{text12}}; __DATA__