use strict; use warnings; use Data::Dumper; my @masterArray = ( ["this", "that", 12563, "something", "else"], ["this", "that", 10, "something", "else"], ["this", "that", 1, "something", "else"], ["this", "that", 125638, "something", "else"], ["this", "that", 300000, "something", "else"], ); my @top3 = sort {$b->[2] <=> $a->[2]} @masterArray[0..2]; my $min_top = $top3[2][2]; for my $sub_aref (@masterArray [3..$#masterArray]) { next if $sub_aref <= $min_top; @top3 = (sort {$b->[2] <=> $a->[2]} @top3, $sub_aref)[0..2]; $min_top = $top3[2][2]; } print Dumper @top3;