sub Remove_duplicate_lines { my ($processed_file, $out_file) = @_; open (PROCESSED_FILE, "<$processed_file"); open (OUTFILE, "+>$out_file"); my @array; my @unique; while () { chomp; push (@array, $_); } my %hash = map { $_, 1 } @array; # or a hash slice: @hash{ @array } = (); # or a foreach: $hash{$_} = 1 foreach ( @array ); my @unique = keys %hash; my @unique = (); my %seen = (); foreach my $elem ( @array ) { next if $seen{ $elem }++; push @unique, $elem; } foreach (@unique){ print OUTFILE "$_"; } }