in reply to 2D arrays

Another problem with the originally posted code is
    push (@{$temp[$i]}, $list[$count]);
        $count += 1;
because  $count just keeps getting bigger and bigger. Try putting a  print $count, "\n"; statement just before the  return @temp; statement in the original  sortList() function definition: is there anything meaningful in  $list[$count] or anywhere near this index?

Another approach is to use the Data::Dump module or one of its ilk and put a dump statement after a call to  sortList() to see what you have:
    use Data::Dump;
    ...
    my @ra = sortList(0..37);
    dd \@ra;