Perl while loop question

Hi,
I am having trouble comparing two files of different lengths and extracting a needed value. File 2 has two columns of information that match up with a value from File 1. I use this as search criteria in an IF statement while both files are open. I would like to print File 1 and add the info from File 2(column 10) on the correct line based on my IF statement. I have never used a while statement before but I think its correct. Does it matter that they are of different lengths? I hope this is clear enough. Any suggestions are appreciated.
Thanks

#!/usr/bin/perl
use strict;
use warnings;
my $haul_file = "mack_haul.txt";
my $lands_files = "mack_land.txt";
open (M,">M.txt") || die "Cant open new";
open ("land",$lands_files) || die "cant open\n";
open ("haul",$haul_file) || die "Cant Open\n";
my @Land;
my @Haul;
my $landslines='';
my $haulline='';

while(my $haulline=<haul>){
   chomp $haulline;
      @Haul=split(/\t/,$haulline);
        while(my $landslines=<land>){
                chomp $landslines;
                @Land =split(/\t/,$landslines);
                                                
                                        
                                if ($Land[3]eq$Haul[2])
                                {
                                   print M "$landslines"."\t$Haul[10]\n";
                                }
                                }}}
 
close(M) || die "GG";
close("haul") || die "Cant close1";
close("land") || die "cant close2";


What will happen in your code is that you will get the first line of "hual" and then read through all the lines of "land" then when you get the second line of "hual" there will be no more lines from "land" to search through because the file pointer for that handle will be at the end of the file. Try this to see what I mean:

#!/usr/bin/perl
use strict;
use warnings;
my $haul_file = "mack_haul.txt";
my $lands_files = "mack_land.txt";
open ("land",$lands_files) || die "cant open\n";
open ("haul",$haul_file) || die "Cant Open\n";

while(my $haulline=<haul>){
   print "[hual] $_";
   while(my $landslines=<land>){
      print "[land] $_";
   }
}
close("haul") || die "Cant close1";
close("land") || die "cant close2";

Side note: use all uppercase characters for filehandles or better use lexical filehandles. lower-case words should be avoided in perl since all of perls built-in functions are all lower-case.

If you need to start the search in "land" from the beginning of the file for each line of "haul" you can use seek() to return the file pointer back to the beginning of the "land" file. See seek() for details.

Thanks Kevin,
I will give that a shot.