my ($configuri) = $basepath."config.xml"; my $cparser = XML::LibXML->new(); # load config file my $config = $cparser->parse_file($configuri); # then an xpath to get to where I want to be foreach my $xsites ($lrconfig->findnodes("//linkrabbitconfig/sites")) { $xnewsite = $config->createElement('site'); $xsites->appendChild($xnewsite); $xsitename = $config->createElement('sitename'); $xnewsite->addChild($xsitename); $xsitename->addChild( $config->createCDATASection($args{'site'}) ); # add a bunch more elements } # output xml file open (XMLfile,">".$configuri); binmode(XMLfile,":utf8"); autoflush XMLfile 1; chmod 0664, $outfile; # dump the xml document to file print XMLfile $config->toString(1); close(XMLfile);