use strict; use warnings; use XML::LibXML; my $xc = XML::LibXML->new; my $node = $xc->parse_string('28344s'); print $node->toString; my $path = '//xID'; my $value = '123'; if (my $subnode = $node->findnodes($path)->[0]) { $subnode->removeChildNodes(); $subnode->appendTextNode( $value ); } print $node->toString;