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" ], ); subDiscarder( \@masterArray ); print Dumper \@masterArray; sub subDiscarder { my ($arrayRef) = @_; my %nums = map $_ => 1, ( sort { $b <=> $a } map $_->[2], @$arrayRef )[ 0 .. 2 ]; @$arrayRef = grep exists $nums{ $_->[2] }, @$arrayRef; } #### $VAR1 = [ [ 'this', 'that', 12563, 'something', 'else' ], [ 'this', 'that', 125638, 'something', 'else' ], [ 'this', 'that', 300000, 'something', 'else' ] ];