@omcees = ("pasys","audsys"); foreach $omc(@omcees){ if ($omc eq "pasys"){$id = "pa"} else{$id = "aud";} $filename = "combine".".txt"; ## May as well test them all now open(FIRST, "/mnt/$omc/ne_data/unload_stats/$currenttime/cel_ntid.unl") or die "Could not open first\n"; open(SECOND, "/mnt/$omc/ne_data/unload_stats/$currenttime/sit_ntid.unl") or die "Could not open second\n"; if ($omc eq "pasys"){ open(THIRD, ">/tmp/$filename" ) or die "Could not write third\n"; } else{ open(THIRD, ">>/tmp/$filename" ) or die "Could not write third\n"; } my (%first, %found); while() { my ($key, @cols) = split(m#\|# => $_, -1); push(@{$first{$key}}, \@cols); $found{$key} = $.; } close(FIRST); while() { my ($one, $key, @cols) = split(m#\|# => $_, -1); if (exists $first{$key}) { delete $found{$key}; for (@{$first{$key}}) { print THIRD $_->[0].$id."|$key|$cols[0]"; print THIRD "|".$_->[0]; print THIRD "\n"; } } } close(SECOND); close(THIRD); }