use strict; use warnings; use XML::Twig; use vars qw (%PARAMS); do 'noname1.pl'; for my $key (keys %PARAMS) { my $val = $PARAMS{$key}; # Need var because sub turns it into a closure $PARAMS{$key} = sub {upd_param (@_, $val)}; } my $twigT= new XML::Twig( twig_roots => \%PARAMS, twig_print_outside_roots => 1, ); $twigT->parse (do {local $/; }); $twigT->purge; #probably not needed sub upd_param { my ($t, $param,$new_param) = @_; my $item = defined($new_param)? $new_param:$param->text; $param->set_text($item); # change it $param->print; # print updated value $t->purge; # free the memory } __DATA__