in reply to Misunderstood array behavior

If you add use strict; use warnings; near the top of your code perl complains that
Global symbol "$sample2" requires explicit package name at...
This is because you are doing the compare outside the inner loop ( where $sample2 is out of scope). Move the if block inside the inner loop and it will run. Fix that first and if it still won't run as expected show us what the first line in both files look like.