my %seen; my @uniq; foreach my $item (@lines) { unless ($seen{$item}) { #if we get here, we have not seen it before $seen{$item} = 1; push(@uniq, $item); } }