#!/bin/perl -w use strict; use XML::Twig; # create and load the twig (with pretty_print option) my $twig= new XML::Twig( pretty_print => 'indented'); $twig->parse( \*DATA); # get the insertion spot, you could also use the get_xpath method my $insert= $twig->root->first_child( 'insert'); # parse the text into a twig element my $text="

this is a paragraph with some XML in it

"; my $elt= parse XML::Twig::Elt( $text); # replace the element by the new one, you # can use $elt->insert to... insert the element $elt->replace( $insert); # out we go! $twig->print; print "\n"; __DATA__ just a filler just another filler