in reply to compare 2 files and print to a third

Provided that the files are not overly large, the following algorithm should suffice -

Step 1 - open the first file, while reading each line, extract the $login from the line, and then add the entry $login => $rest_of_the_line in a hash table.

Step 2 - open the second file, while reading each line, extract the $login from the line, and then look up the $login in the hash table built from the first file.

Step 3 - if a match is found, then do compare/combine/whatever with the data stored in the hash table and the data held in current line. Output the result to the third file.

Ok, sounds like you need some code...
use strict; use IO::File; my %data; # hash to store data from first file my $f = new IO::File "first.txt", "r" or die "Can't open file 1"; while (<$f>) { chomp; my ($login) = /^(\w+):/; $data{$login} = $_; } undef $f; my $f = new IO::File "second.txt", "r" or die "Can't open file 2"; my $o = new IO::File "third.txt", "w" or die "Can't create file 3"; while (<$f>) { chomp; my ($login,$info) = /^(\w+)(:.*)/; if ($data{$login}) { print $o $data{$login} . $info, "\n"; } } undef $f; undef $o;
And the files -
---- first.txt ---- 0001:rec1:rec2:rec3 0002:recA:recB:recC 0003:recX:recY:recZ ---- second.txt ---- 0001:rec4:rec5:rec6 0002:recD:recE:recF
The output file -
---- third.txt ---- 0001:rec1:rec2:rec3:rec4:rec5:rec6 0002:recA:recB:recC:recD:recE:recF