@Tree = sort { my $la = @{ $a->{Path} }; #length of left side my $lb = @{ $b->{Path} }; # ~ of right side my $r; # r = return for( 0 .. ($la > $lb ? $lb : $la) ){ $r = $a->{Path}[$_] <=> $b->{Path}[$_] and return $r #return if not 0 } $r #return last comparison } @Tree; # HTH