use XML::Rules; my $AC_n = 'CCC'; my $parser = XML::Rules->new( rules => [ _default => 'as is', # by default keep both attributes and _content 'Desc,What,AR' => 'content', # for those keep just the content '^AC' => sub {return ($_[1]->{n} eq $AC_n)}, # only process the tags whose n attribute equals the $AC_n AC => '', # once processed, forget the contents of the tag AI => sub {print "Found AI: n=$_[1]->{n}, desc=$_[1]->{Desc}\n"; return}, # for each processed AI tag print the n attribute and Desc subtag. # thanks to the 2nd rule you don't have to write # $_[1]->{Desc}{_contents} # As this rule returns nothing, the contents of the tag are not remembered. ], ); $parser->parse($XML);