print "@firstLine1\n"; print "@firstLine2\n"; #### open my $fileText, '<', $file or die("Error opening \"$ARGV[0]\": $! "); my @firstLine1; my $count = 0; while(<$fileText>){ chomp; if($count++ == 0){ # I will eventually read the whole file... @firstLine1 = split(/\t/); last; } } open my $fileText2, '<', $ARGV[1] or die("Error opening \"$ARGV[1]\": $! "); my @firstLine2; $count = 0; while(<$fileText2>){ chomp; if($count++ == 0){ # I will eventually read the whole file... @firstLine2 = split(/\t/); last; } } print "@firstLine1\n"; # All values print fine! print "@firstLine2\n"; # All values print fine! foreach my $sample1 (@firstLine1){ foreach my $sample2 (@firstLine2){ # I get some strange output here. # Everything will print fine -> # $sample1: $sample2: # until the last value in the array, # everything gets messed up -> # sample1:$sample2: print "\$sample1: \"$sample1\"\t\$sample2: \"$sample2\"\n"; } # If I try a compare, it fails if($sample1 eq $sample2){ # doesn't get here on the last value. } }