sub gettag { my $self = shift; ($self -> { THIS }{ DEPTH } ||= 0)++; my $tagref = { SUBTAG => [] }; # ... while ( !/<\// ) { push @{$tagref -> { SUBTAG }}, $self -> gettag(); # recursive call } # ... $self -> { THIS }{ DEPTH }--; return $tagref; }