Well, I'd prefer to leave the array in the order given (just in case the user wants it that way), but if you wanted it sorted you could do one of two things:
- Replace the line return @expanded; with return sort @expanded;
- When calling it, just sort the results. Ex/ my @results = sort expandRange($string);