foreach @line (@data) { for my $tree (0..17) { for my $stem (0..10) { for my $height (0..2) { if (@line[0]==$tree and @line[1]==$stem and @line[2]==$height) { if (defined $mdarray[$tree][$stem][$height]) { print "there's a duplicate stem!\n" } else { $mdarray[$tree][$stem][$height]=[@line]; } } } } } } print "Test: @{$mdarray[1][1][1]}\n";