in reply to searching the XML file for certain nodes

XML::Twig is particularly well suited to do this transformation. Sorry, I don't have time to come up with the code right now.

Update: Contrary to claims made, that's not XML. 1 and 2 are not valid XML element names. If that isn't what you are actually using, the following code will do the trick:

use strict; use warnings; use XML::Twig; my $t = XML::Twig->new( twig_handlers => { 'p[@v!="YES"]' => sub { $_->delete }, }, ); $t->parse(\*DATA); # $t->parsefile( "file.xml"); $t->flush(); __DATA__ <?xml version="1.0" encoding="UTF-8" ?> <e> <p id="1" v="YES"> <c>The</c> <c>Bye</c> </p> <p id="2" v="NO"> <c>Border</c> <c>Lamp</c> </p> </e>