while ($parent = $tree{$parent}{parent}[0]) { if ( $parent eq 'Q' ) {next;}