use Net::EPP::Frame; my $frame = Net::EPP::Frame::Command::Update::Contact->new; #... my $xpc = XML::LibXML::XPathContext->new($frame); $xpc->registerNs('contact', 'urn:ietf:params:xml:ns:contact-1.0'); for my $name (qw(rem add)) { for my $node ($xpc->findnodes("//contact:$name".'[not(*|text()|@*|processing-instruction()|comment())]', $frame->documentElement)) { $node = $node->parentNode->removeChild($node); } } print $frame->toString(1);