in reply to Sort array according to a value in each element?

I'm sorry, I just had to do it in one line. ;-)

my @array = ( 'Item1 - 1 foo, 2 bar', 'Item2 - 16 foo, 8 bar', 'Item3 - 0 foo, 1 bar', 'Item4 - 1 foo, 3 bar', 'Item5 - 4 foo, 12 bar', 'Item6 - 2 foo, 2 bar', ); @sortedArray = sort {($b=~/(\d+) bar/)[0] <=> ($a=~/(\d+) bar/)[0]} @array; $"="\n"; print "@sortedArray\n"; # sort by two fields @sortedArray = sort { ($b=~/(\d+) bar/)[0] <=> ($a=~/(\d+) bar/)[0] || ($b=~/(\d+) foo/)[0] <=> ($a=~/(\d+) foo/)[0] } @array; print "\n@sortedArray\n";