use Unicode::Collate; my $collator = Unicode::Collate::->new(); # first calculate the magic sort key for each text field, and cache it for my $rec (@recs) {     $rec->{SURNAME_key} = $collator->getSortKey( $rec->{SURNAME} ); }  # now sort the records as before, but for the surname field, # use the cached sort key instead @srecs = sort {     $b->{AGE}          <=>  $b->{AGE}                       ||     $a->{SURNAME_key}  cmp  $b->{SURNAME_key} } @recs;