in reply to Deleting nodes with HTML::TreeBuilder::XPath

If you are open to alternatives this uses Mojo::DOM:

#!/usr/bin/perl use strict; use warnings; use Mojo::DOM; my $html = '<ul><li>1</li><li>2</li><li></li><li>4</li><li></li><li>si +x</li>'; my $dom = Mojo::DOM->new( $html ); for ( $dom->find('li:empty')->each ){ $_->remove(); } print "$dom\n";

Update: output: <ul><li>1</li><li>2</li><li>4</li><li>six</li></ul>