my @sorted= do { my @sorton= map { get_date($_) } @data; my @indices= sort { $sorton[$a] cmp $sorton[$b] } 0..@data; @data[@indices]; };