in reply to Index sorting

This is a case for normal Perl, not a module, IMHO. :) I leave it to you to update the ID's once it's sorted, but how about this:
sub by_level { my $tempa =~ s/^<.*">//; $tempa =~ s/<\/.*>//; my $tempb =~ s/^<.*">//; $tempb =~ s/<\/.*>//; substr($a,0,2) cmp substr($b,0,2) || $tempa cmp $tempb; }
Update: added " to first $tempb substitution. Untested, but I think this does what you want.