 <pre><code>use HTML::TreeBuilder; my $t = HTML::TreeBuilder-&gt;new-&gt;parse_file("China.data"); sub list {my ($t, $d) = @_; $d //= 0; if (ref($t)) {say " "x$d, $t-&gt;tag; for($t-&gt;content_list) {list($_, $d+1); } } else {say " "x$d, dump($t)} } </code></pre> <p>list($t);</p>