my @data = map { s/\A (.*)(.) \z/$2$1/x } sort map { s/\A (.)(.*) \z/$2$1/x } @tempArray;