while ($line_f1 = ) { while($line_f2 = ) { # I'm sure the rest you can do it } seek(FILE2,0,0); }