use strict; use warnings; use XML::Simple; my $config = XMLin('foo.xml', ForceArray => [qw(tab button)]); my @tabs = @{$config->{notebook_tabs}{tab}}; my $n = 1; for my $t (@tabs) { print "In tab No. $n\n"; if (exists $t->{button}) { print "\t found ", scalar(@{$t->{button}}), " button\n"; } else { print "\t no tabs\n"; } $n++; } __END__ In tab No. 1 found 2 button In tab No. 2 no tabs