use strict; use XML::Twig; my $twig = new XML::Twig( twig_handlers => { sec => sub { $_->set_gi('section') }, #change the element }, keep_encoding => 1, keep_spaces => 1, pretty_print => 'indented' #print format ); $twig->parsefile('1.xml');