my $xfile = < feature_one 2 R 4 V feature_two 5 S EOF use strict; use warnings; use XML::Twig; my $twig= new XML::Twig( twig_handlers => { feature => \&feature } ); $twig->parse($xfile); sub feature { my ($twig, $feat) = @_; if ($feat->first_child('feature_name')->text() eq 'feature_one') { for my $res ($feat->findnodes('residues/residue')) { my $res_idx = $res->first_child('residue_index')->text(); my $res_name = $res->first_child('residue_name' )->text(); print "$res_idx $res_name\n"; } } } __END__ 2 R 4 V