#!/usr/bin/perl use strict; use warnings; use XML::LibXML; use XML::LibXML::XPathContext; my $parser = XML::LibXML->new(); my $doc = $parser->parse_fh(\*DATA); my $xc = XML::LibXML::XPathContext->new( $doc->documentElement() ); $xc->registerNs( text => 'urn:oasis:names:tc:opendocument:xmlns:text:1.0' ); my $xpath = q{//text:p[@text:style-name="VariableTextSurname"]}; foreach my $p ($xc->findnodes($xpath)) { print "Found a variable para\n " . $p->to_literal . "\n"; # could do e.g.: $p->parentNode->removeChild($p); } # After manipulations, serialise back to XML with: # my $xml = $doc->toString(); exit; __DATA__ Paragraph OneParagraph TwoParagraph Three