#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use HTML::Parser; my $pa = qq~

This is a bad try to display text then code

#! usr/bin/perl
use strict;
use warnings;

print "Hello World!";
and then plain text again

~; my $parser = HTML::Parser->new( start_h => [ \&_starttag, 'self, tagname, attr' ], end_h => [ \&_endtag, 'self, tagname' ], text_h => [ \&_text, 'self, dtext' ] ); $parser->parse($pa); sub _starttag { my ($self, $tag, $attr) = @_; $self->{'_body'} = 1 if ($tag eq 'body'); } sub _endtag { my ($self, $tag) = @_; $self->{'_body'} = undef if ($tag eq 'body'); } sub _text { my ($self, $dtext) = @_; $dtext =~ s/\A\s+//; $dtext =~ s/\s+\z//; return() unless ( length($dtext) > 0 and $dtext =~ /[^\s]/ ); if ( defined($self->{'_body'}) ) { print $dtext," "; } }