use strict; open (IN, "test.txt") or die "Can't open file: $!"; open (UNQ, "> unq.txt") or die "Can't open file: $!"; open (DUP, "> dup.txt") or die "Can't open file: $!"; my %hash; while () { chomp; $hash{$_}++; } foreach (keys %hash) { if ( $hash{$_} > 1) { print DUP "$_\n"; } else { print UNQ "$_\n"; } } __END__ fraser:~$cat test.txt 0000 1111 2222 3333 4444 0000 3333 1111 5555 1111 0000 0000 1111 3333 6666 0000 fraser:~$cat unq.txt 6666 4444 2222 5555 fraser:~$cat dup.txt 0000 3333 1111 fraser:~$