in reply to How do we remove specific HTML element

XML::LibXML can open HTML.
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $html = 'XML::LibXML'->load_html(location => 'file.html', recover => 1); my $nav2 = $html->find('(//nav)[2]')->[0]; $nav2->parentNode->removeChild($nav2); print $html->toString; # c="d" is gone.

Or, more succinctly in XML::XSH2:

open :r :F html file.html ; rm (//nav)[2] ; ls / ;

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.