use XML::Twig; open my $ofh, '>', \my $outxml or die $!; my $twig = XML::Twig->new( twig_print_outside_roots => $ofh, twig_roots => { '/includes/include/priority' => sub { my ($twig, $elt) = @_; $elt->set_text( $elt->text+1 ); $elt->flush($ofh); }, } ); $twig->parse($xml); close $ofh; print $outxml;