my $sel = 'title'; my $twig = XML::Twig->new( pretty_print => 'indented', twig_roots => { "$sel" => \&parse_title }, ); $twig->parsefile('1.xml'); $twig->print; sub parse_title { my ($t,$title) = @_; $title->delete if $title->get_xpath( 'name/fnm[@letter="a"]' ); } #### testing<name><snm>Houston</snm>, <fnm letter="c">Carl</fnm></name><g>69</g><ppg>20.1</ppg><rpg>3.4</rpg><apg>2.8</apg><blk>14</blk> testign <name>Houston <fnm j="b">Bob</fnm><g>49</g><title> testing the sub title in title this is pcdata in subtitle <title> second sub level