The Schwartz transformation would be a huge waste here. This similar construction, whose name I will never remember, would be better.
my @sorted =
map substr($_, 4),
sort
map substr($_, -2) . substr($_, -4, 2) . $_,
@unsorted;
Using the match operator instead of substr:
my @sorted =
map substr($_, 4),
sort
map { /(..)(..)\z/s; $2.$1.$_ }
@unsorted;
source
share