in reply to Parse variables

my @sorted_recs = sort { $$records[$a][2] <=> $$records[$b][2] } @reco +rds;

You're treating $records as a reference to an array, yet you don't even have such a variable.

$a and $b are aliased to the two elements of @records that need to be compared. The elements of @records are references to records (arrays of 6 fields).

my @sorted_recs = sort { $a->[2] <=> $b->[2] } @records;