use strict; use warnings; use diagnostics; use HTML::TreeBuilder::LibXML; my $body; while () { $body .= $_; } my $tree = HTML::TreeBuilder::LibXML->new_from_content($body); my $xpath = '//div[@class="ccc"]/node()'; my @superCats = $tree->findnodes($xpath); $tree->delete; for my $superCat(@superCats) { my $sc = ${$superCat->parent}{'node'}; print "$sc\n\n"; } exit; __DATA__

Hello

All