sub remove_duplicates(\@) { my $ar = shift; my %seen; for ( my $i = 0; $i <= $#{$ar} ; ) { splice @$ar, --$i, 1 if $seen{$ar->[$i++]}++; } } my @a = qw( a a b c c c d e f e f e a f g h h h ); remove_duplicates( @a ); print "@a\n";