use strict; use warnings; use XML::Twig; open my $XML, '>', 'temp.xml'; print $XML < XML close $XML; my $twig = XML::Twig->new ( twig_roots => {elt => \&FixName}, twig_print_outside_roots => 1 ); $twig->parsefile_inplace ('temp.xml', '.bak'); $twig = 0; @ARGV = 'temp.xml'; print "::$_" while <>; sub FixName { my ($t, $elt) = @_; $elt->set_att ('attr', 'updated'); $elt->print (); } #### :: :: ::