$_ = "Priority Kirkgate, PC7588\n"; @fields = split /,/, $_ ; print "PC string from NEW list: >>$fields[1]<<"; #### use strict; my %new_pc; ... while () { chomp; $count_in++; @fields = split /,/, $_; $PC_NO = $fields[1]; $PC_NO =~ s/\s*//g; $new_pc{ $PC_NO } = 1; }; ... while () { chomp; if (/CN=(PC\d+)\.OU/) { my $pc = $1; if (exists $new_pc{ $pc }) { # $pc is old and new, hence has survived delete $new_pc{ $pc }; } else { # $pc is old but not new, hence has been removed }; } else { warn "Ignoring line >>$_<<"; }; }; # All PCs in %new are now really new: for my $pc (keys %new) { print "$pc is new\n"; };