sub smartcomp { my @first = ($a =~ /(\D*)(\d*)/g); my @second = ($b =~ /(\D*)(\d*)/g); while (@first and @second) { my $one = uc shift @first; my $two = uc shift @second; my $cmp = $one cmp $two; return $cmp if $cmp; # Case-insensitive comp on string $one = shift @first; $two = shift @second; $cmp = $one <=> $two; return $cmp if $cmp; # Numerical sort on digits } # Check to see which ran out first. if (@first) { return -1; } elsif (@second) { return 1; } else { # And finally a case-sensitive comparison return ($a cmp $b); } }