Marpa::HTML is a Perl module that does "high-level" parsing of HTML. It allows handlers to be specified for elements, terminals and other components in the hierarchical structure of an HTML document. Marpa::HTML is an extremely liberal HTML parser. Marpa::HTML does not reject any documents, no mater how poorly they fit the HTML standards. SYNOPSIS Delete all tables: use Marpa::HTML qw(html); my $with_table = 'TextI am a cell More Text'; my $no_table = html( \$with_table, { table = > sub { return q{} } }); Delete everything but tables: my %handlers_to_keep_only_tables = ( table = > sub { return Marpa::HTML::original() }, ':TOP' = > sub { return \( join q{}, @{ Marpa::HTML::values() } ) } ); my $only_table = html( \$with_table, \%handlers_to_keep_only_tables ); The above works by turning the original text of the HTML into values and concatenating the values at the top of the parse. The same logic works even if a table is very defective: my $with_bad_table = 'TextI am a cell More Text'; my $only_bad_table = html( \$with_bad_table, \%handlers_to_keep_only_tables ); Delete all comments: my $with_comment = 'Text I am not a comment'; my $no_comment = html( \$with_comment, { ':COMMENT' = > sub { return q{} } }); By default, text is passed through unchanged, so that the user need only specify semantic actions for those components she wants changed. To change the title of a document: my $old_title = 'Old TitleA little html text'; my $new_title = html( \$old_title, { 'title' => sub { return 'New Title' } } ); Delete all elements with a class attribute of "delete_me": my $stuff_to_be_edited = 'ABC'; my $edited_stuff = html( \$stuff_to_be_edited, { '.delete_me' => sub { return q{} } }); Marpa::HTML recognizes elements even if they have missing start and/or end tags. Marpa::HTML can supply missing tags: sub supply_missing_tags { my $tagname = Marpa::HTML::tagname(); return if $empty_elements{$tagname}; return ( Marpa::HTML::start_tag() // "\n" ) . Marpa::HTML::contents() . ( Marpa::HTML::end_tag() // "\n" ); } my $html_with_just_a_title = 'I am a title and That is IT!'; my $valid_html_with_all_tags = html( \$html_with_just_a_title, { q{*} => \&supply_missing_tags } ); Marpa::HTML understands the hierarchical structure of an HTML document. Finding the maximum nesting depth in elements is straightforward: sub depth_below_me { return List::Util::max( 0, @{ Marpa::HTML::values() } ); } my %handlers_to_calculate_maximum_element_depth = ( q{*} = > sub { return 1 + depth_below_me() }, ':TOP' = > sub { return depth_below_me() }, ); my $maximum_depth_with_just_a_title = html( \$html_with_just_a_title, \%handlers_to_calculate_maximum_element_depth ); Marpa::HTML tracks actual elements, however tagged. The above code returns the same depth for $valid_html_with_all_tags as for $html_with_just_a_title. Requirements: