open (OUT, ">output.txt"); open (IN, "input1.txt");->original file1 with all data while($line=){ chomp($line); ($Date,$MTime,$inserdate,$inserttime,$Id,$Phase,$Size,$day,$order)= split(/ /,$line); open (INL, "file2.txt");-->contains the sorted order values of order values($x) from file 1 while($linel=){ chomp($linel); ($x,$y,$z,$q,$t)= split(/ /,$linel); if($x == $order) { #print OUT "$a $x $b $z $q $t \n"; print OUT $Date," ",$M_Time," ",$inserdate," ",$y," ",$Id," ",$Phase," ",$Size," ",$day," ",$order,"\n"; } } } close(INL); close(IN); close(OUT); print "DONE";