#!/usr/bin/perl use strict; use warnings; my $file = "controls.txt"; # always(!!!) use the three argument form of open open (FH, "<", $file) or die "Can't open $file for read: $!"; my @lines; while () { chomp; push (@lines, $_); } close(FH) or die "Cannot close $file: $!"; my %seen = (); my @uniq = (); foreach my $line ( @lines ) { unless ($seen{$line}) { #if we get here, we have not seen it before $seen{$line} = 1; push(@uniq, $line); } } print join(", ",@uniq) , "\n"; # see if it worked #### 1 1 2 3 3 3 3 3 5 5 6 6 7 7 #### 1, 2, 3, 5, 6, 7