my $data=<foo

h4.1

bar

baz

h4.2

bar

baz

h4.3


bar

baz DATA { package MyParser; use base 'HTML::Parser'; sub start { my($self, $tagname, $attr, $attrseq, $origtext) = @_; if ( $self->{blockquote} ) { # deal with no closing

print "\n$origtext"; $self->{blockquote} = 0; } elsif ( $tagname eq 'p' and $self->{h4last} ) { print '
'; $self->{blockquote} = 1; } else { print $origtext; } $self->{h4last} = $tagname eq 'h4' ? 1 : 0; } sub end { my($self, $tagname, $origtext) = @_; if ( $self->{blockquote} and $tagname eq 'p' ) { print '
'; $self->{blockquote} = 0; } else { print $origtext; } } sub text { my($self, $origtext, $is_cdata) = @_; print $origtext; } sub comment { my($self, $origtext ) = @_; print $origtext; } } my $p = MyParser->new; $p->parse($data);