use strict; use XML::Twig; my $sel = 'title'; my $ign = 'title/name/fnm[@letter="a"]'; my $twig = XML::Twig->new( ignore_elts => { "$ign" => 1}, twig_roots => { "$sel" => 1}, pretty_print => 'indented' ); $twig->parsefile('1.xml'); $twig->print; #### 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> testing<name><snm>Houston</snm>, <fnm letter="a">Allan</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 This is a test #### 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">Beb</fnm><g>49</g><title> testing the sub title in title this is pcdata in subtitle <title> second sub level #### 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> testing<name><snm>Houston</snm>, </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">Beb</fnm><g>49</g><title> testing the sub title in title this is pcdata in subtitle <title> second sub level