my $new_outputfile = $outputfile."_B"; open (RESULT_FILE, "<$outputfile"); open (CLEANED_RESULT, "+>$new_outputfile"); our @data = ; chomp @data; my %seen; for ( @data) { next if $seen{$_}++; print CLEANED_RESULT "$_\n"; } remove $outputfile or warn $!; rename "$new_outputfile", "$outputfile" or warn $!;