{ package MyParser; use base 'HTML::Parser'; sub start { my($self, $tagname, $attr, $attrseq, $origtext) = @_; $self->{table}++ if $tagname eq 'table'; $self->{data} .= $origtext unless $self->{table}; } sub end { my($self, $tagname, $origtext) = @_; $self->{data} .= "$tagname>" unless $self->{table}; $self->{table}-- if $tagname eq 'table'; } sub text { my($self, $origtext, $is_cdata) = @_; $self->{data} .= $origtext unless $self->{table}; } sub comment { my($self, $origtext ) = @_; #$self->{data} .= $origtext if $want_comments } } my $p = MyParser->new; $p->parse_file(*DATA); $data = $p->{data}; print $data; __DATA__
Hello
World
REs can be useful, but HTML parser rocks!