#!/usr/bin/perl -- use XML::Twig; BEGIN { *XML::Twig::Elt::x = *XML::Twig::Elt::get_xpath; } use strict; use warnings; my $str = <<'EOF'; qqqqq welcome abcde welcome EOF { my $t = XML::Twig->new( pretty_print => 'indented', twig_handlers => { '//factory/drop' => sub { if ( not $_->x('bindname[string()=~/abcde/]') ) { if ( my ($pass) = $_->x('bindpass[string()="welcome"]') ) { $pass->set_text( uc $pass->text ); } } }, }, ); $t->parse($str); $t->print(); } { my $bozo = 0; my $t = XML::Twig->new( pretty_print => 'indented', twig_handlers => { '//factory/drop/bindname' => sub { $bozo = 1 if $_->text =~ /abcde/; }, '//factory/drop/bindpass' => sub { if ( not $bozo and $_->text =~ /welcome/ ) { $_->set_text( uc $_->text ); } $bozo = 0; }, }, ); $t->parse($str); $t->print(); } __END__