my %tagstack; # ... parsing code here push @{$tagstack{requirements}}, { # $tag = wherever the data is coming from text => $tag{cdata}, attributes => $tag{attribs} };