I've written the following, it is very crude but works till the last step, where it has to paste two lines only if their ID's are the same.
#!/usr/bin/perl -w
use warnings;
######## READING FILE ONE ##########
$[ = 1;
open(DATA, "< list1") or die "Failed to open list1";
open(MYOUT1, ">...