my $file = "project.txt"; # Use three-argument form of open() (available in perl 5.6.0) # and check the return value. open(FILE, '<', $project) or die "Can't open $project: $!\n"; my %input; while(my $line = ) { chomp $line; # Get rid of whitespace (newline) at the end of the string if($line =~ /\tCM+(\d*)/io) { $input{$1}++; } } close(FILE); #### open(OUT, '>>', 'project.out') or die "Can't open project.out for writing: $!\n"; foreach my $i (keys %input) { print OUT "$i\n" unless $input{$i} > 1; } close OUT;