for my $record ($root->children) { my @tmp=(); for my $col (@cols){ if (defined $record->first_child($col)){ push @tmp,$record->first_child($col)->text; } else { push @tmp,'';; } } push @data,[ @tmp ]; }