sub alpha_num_cmp { my($a, $b) = @_; if (( $a =~ m/\D/) || ($b =~ m/\D/)) { #look for a non-digit return ($a cmp $b); #if so, then use string compare } return ($a <=> $b); #otherwise straight numeric comparison }