in reply to Array Sort

You can pick any of the advanced sorting techiques as described in Uri Guttman + Larry Rosler's paper: A Fresh Look at Efficient Perl Sorting. Just for practice.

If you don't really care about efficiency, or just to get a feel as what's going on, you can call a function for each items every single time.

# for example, this'll do what you want sub extract_middle { return shift() =~ /-(.*)-/ ? $1 : '' } @sorted = sort { extract_middle($a) cmp extract_middle($b) } @unsorted +;
Note that the speedups as described in the paper are achieved by essentially calling this extract function only once for each item.

update Fixed a bug in the sub, thanks moritz