#!/usr/bin/perl -w use strict; use XML::Twig; my $USAGE= "$0 "; die $USAGE unless( @ARGV == 3); my( $file, $path, $value)= @ARGV; # $_ is set to the current element in the handler # you could also delete the element after printing it # for even less memory usage my $twig= XML::Twig->new( twig_roots => { $path => sub { $_->set_text( $value); $_->print; } }, twig_print_outside_roots => 1, ); $twig->parsefile( $file);