http://www.perlmonks.org?node_id=418602

#!/usr/bin/perl -w use strict; use HTML::Parser 3.00 (); my %inside; my $parser = HTML::Parser->new(api_version => 3, handlers => [start => [\&tag, "tagname, '+1'"], end => [\&tag, "tagname, '-1'"], text => [\&text, "dtext"], ], marked_sections => 1, ); #my ($title, $text)= strip("perl/perlmain.html"); print $title, $tex +t; print strip("perl/perlmain.html"); sub strip { my $text; our $title; $parser->parse_file(shift) || die "Can't open file: $!\n"; #print $title,$text; return $title, $text; } sub tag { my($tag, $num) = @_; $inside{$tag} += $num; #print " "; # not for all tags } sub text { return if $inside{script} || $inside{style}; if ($inside{title}) { $title .= $_[0]; return; } $text .= $_[0]; #print $_[0]; }