#!/usr/bin/perl -w use strict; use HTML::TokeParser::Simple 1.4; my $parser = HTML::TokeParser::Simple->new( *DATA ); my $html = ''; my $not_balanced = 0; while ( my $token = $parser->get_token ) { $html .= $token->as_is unless $not_balanced; if ( $token->is_tag('table') ) { $not_balanced += $token->is_start_tag ? 1 : -1; # ugh, I don't like the double negative $html .= $token->as_is if $token->is_end_tag and ! $not_balanced; } } print $html; __DATA__

one

test

two