use HTML::Parser; my $parser = HTML::Parser->new( start_h => [ \&_starttag, 'self, tagname, attr' ], end_h => [ \&_endtag, 'self, tagname' ], text_h => [ \&_text, 'self, dtext' ] ); $parser->parse($email_text); sub _starttag { my ($self, $tag, $attr) = @_; $self->{'_body'} = 1 if($tag eq 'body'); } sub _endtag { my ($self, $tag) = @_; $self->{'_body' } = 0 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 ($self->{'_body'} == 1) { print $dtext; } }