my @time_limits; my $t = XML::Twig->new( twig_handlers => { timeLimit => sub { my $atts = $_->atts; if (exists $atts->{startTime} && exists $atts->{endTime}) { push @time_limits, [$atts->{startTime}, $atts->{endTime}]; } }, }, ); $t->parse($xml); print "[$_->[0]], [$_->[1]]\n" foreach @time_limits;