add_id Add an id to the element. The id is an attribute (id by default, see the id option for XML::Twig new to change it. Use an id starting with # to get an id that's not output by print, flush or sprint) that allows you to use the elt_id method to get the element easily. set_id_seed ($prefix) by default the id generated by add_id is twig_id_, set_id_seed changes the prefix to $prefix and resets the number to 1 #### use strict; use XML::Twig; my $string = '

here the paragraph comes

here the paragraph comes

here the paragraph comes

'; my $twig = new XML::Twig( twig_handlers => { p => sub { $_->add_id() }, #insert element id }, pretty_print => 'indented' #print format ); $twig->set_id_seed( '' ); $twig->parse($string); $string = $twig->sprint; print $string; output: -------

here the paragraph comes

here the paragraph comes

here the paragraph comes