use XML::Twig; use strict; use warnings; my $data = do {local $/; }; my $twig = new XML::Twig(twig_handlers => { '//target[@type="aim"]/*' => sub { print $_->tag, ' ', $_->text, "\n"; }, }); $twig->parse($data); __DATA__ 123 456 234