my %seen; for my $key (0 1 2 1 2 3 2 3 4 3 4 5) { print $key unless $seen{$key}++; }