This script prints the name of each element it finds and it's depth in the tree.
use XML::Parser; my $deep = 0; my $parser = new XML::Parser(Handlers => {Start => \&handle_start, End => \&handle_end}); $parser->parsefile($ARGV[0]); sub handle_start { my $p = shift; my $el = shift; $deep++; print "$el - $deep\n"; } sub handle_end { $deep--; }