my $xp = XML::XPath->new(xml => $fpdomaininfo ); my $nodeset = $xp->find('//cidr-map'); foreach my $node ($nodeset->get_nodelist) { my $node_name = $node->findvalue ( '@name' ) -> string_value; my $ips_as_string = $node->string_value; ... make changes to ips_as_string ... } #### my $path = '//cidr-map[@name]='; $path .= "\"$node_name\"; $xp->setNodeText( $path, $ips_as_string ); #### my $path = '//cidr-map/cidr-map-to[@name]='; $path .= "\"$node_name\"; $xp->setNodeText( $path, $ips_as_string ); #### ... 127.0.241.174 127.0.0.181 127.0.12.1 10.0.0.1 198.168.1.1 ...