#!/usr/bin/perl use warnings; use strict; use HTML::TokeParser; my $html = do{local $/;}; my $p = HTML::TokeParser->new(\$html); # find the start of the table while (my $t = $p->get_token){ last if( $t->[0] eq q{S} and $t->[1] eq q{table} and ${$t->[2]}{class}, and ${$t->[2]}{class} eq q{details} ); } my ($in_td); while (my $t = $p->get_token){ # quit loop when we find the end of the table last if( $t->[0] eq q{E} and $t->[1] eq q{table} ); $in_td++, next if $t->[0] eq q{S} and $t->[1] eq q{td}; $in_td--, next if $t->[0] eq q{E} and $t->[1] eq q{td}; next unless $in_td; # if we are here we must be in a td tag if ($t->[0] eq q{T}){ print qq{**$t->[1]**\n}; } } __DATA__ table
detail 1 detail 2
detail 3 detail 4
#### **detail 1** **detail 2** **detail 3** **detail 4**