use strict; use warnings; use XML::Twig; my $xmlStr = < hello bye later XML my $twig= XML::Twig->new(); $twig->parse($xmlStr); my $elt = $twig->root(); my @qps = $elt->children('qp'); my $numOfQuotes = 0; for my $qp (@qps) { for my $q ($qp->children( qr/^(q|xr)$/ )) { $numOfQuotes++ if $q->att('supp') eq 'yes'; } } print "numOfQuotes = $numOfQuotes\n"; __END__ numOfQuotes = 2