#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use XML::Twig; my $xmlStr = < XML my @ids; my $t = XML::Twig->new(); $t->parse($xmlStr); for my $one ( ($t->root()->children('one') ) { for my $month ( ($t->root()->children('monthly') ) { if ( $momth->att('value') eq 'on' ) { push @ids, $one->att('id'); } } } print Dumper(\@ids);