my %USERS; my @all_strips = (); ## <-- new foreach my $file () { open(PASSWD,$file) or warn "Could not open $file:$!\n", next; my $strip=$file; #strips passwd. from passwd.server $strip =~ s/passwds\.//; push(@all_strips, $strip); ## <-- new while() { my($login,$gcos) = (split(':',$_))[0,4]; $USERS{$login}{$strip} = 1; ## This way you keep track of ## which login/strip combinations ## have been seen } close(PASSWD); } open(NEWFILE,">file3") or die "Can't open file3: $!\n"; foreach my $login (sort keys %USERS) { print NEWFILE "$login:", # Substitute X in where no strip was found join(':', map { $USERS{$login}{$_} ? $_ : 'X' } @all_strips), "\n"; } close NEWFILE; print "the Active Servers listing is done\n";