my $length = $#MainArray; for (my $x = 0; $x <= $length; $x++) { my $smallLength = $MainArray[$#$x]; for(my $q = 0; $q <= $smallLength; $q++) { my $element = $MainArray[$x][$q]; if(some if statement concerning $element) { splice(How do I reference this part?); } } }