in reply to Coredump error.

It appears to be the sort that is causing the crash. This is 'a bit' dubious because you are referring to the same array in the sort cmp as well as in the result. I suggest:
{ my @sortkey2 = sort { lc($names[$sortkey[$a]]) cmp lc($names[$sortkey[$b]]) } @sortkey; @sortkey = @sortkey2; }
BTW the parentheses make no difference, but are not necessary (and I'm sure you can think of a better way to print the array ;-)).