in reply to sorting and array by [2]

your code looks quite weird. if you want to sort then use sort and not map! ;)
@sorted = sort { $a->[2] <=> $b->[2] } <INPUT>; chomp (@sorted);