while(my $token = $stream->get_token) { if ($token->[0] eq 'S' and $token->[1] eq 'span' and ($token->[2]{'id'} || '') eq 'fulldescription') { #found the tag if ($token->[0][0] eq 'S' and $token->[0][1] eq 'div' and ($token->[0][2]{'class'} || '') eq 'text12') { print $stream->get_trimmed_text('/div'); } } }