$file = "project.txt"; open(FILE,"$file"); my %hash = (); while(my $a=) { if($a=~/\tCM+(\d*)/io) { print "$1\n"; $hash{$1}=undef; } } close FILE; open(OUTPUT,">> project.out"); while(my $key = each %hash) { print OUTPUT "$key\n"; } close OUTPUT; #### my %done=(); open INPUT, "<$inputfile"; open OUTPUT, ">>$outputfile"; while() { next unless /\tCM+(\d+)/io; next if exists $done{$1}; print OUTPUT, "$1\n"; $done{$1}=undef; ) close INPUT; close OUTPUT;