use strict; use warnings; my $html = q|

blah

blah

blah

blah

blah

blah

blah blah blah

blah

blah

blah

blah

|; my $parser = Markdent_Parser->new(); $parser->parse($html); $parser->eof; print $parser->out; package Markdent_Parser; use parent qw(HTML::Parser); sub start { my ($self,$tag,$attr,$attrseq,$text) = @_; if ($tag eq 'h1' and $self->{'in_h2'}) { $self->{'out'} .= "\n\n"; $self->{'in_h2'} = 0; } elsif ($tag eq 'h2') { if ($self->{'in_h2'}) { $self->{'out'} .= "\n"; } $self->{'out'} .= "\n
\n"; $self->{'in_h2'} = 1; } $self->{'out'} .= $text; } sub text { my ($self,$text) = @_; $self->{'out'} .= $text; } sub end { my ($self,$tag,$text) = @_; $self->{'out'} .= $text; } sub out { my ($self) = @_; if ($self->{'in_h2'}) { $self->{'out'} .= "\n
"; } return $self->{'out'}; } 1;