use strict; use warnings; use Benchmark; Benchmark::cmpthese(-1,{ 'shift' => sub { my (%seen, $string); my @array = (0..1000, 0..1000); $seen{$string}++ while $string = shift @array; for (keys %seen) { push @array, $_; delete $seen{$_}; } }, 'grep' => sub { my %seen; my @array = (0..1000, 0..1000); my @unique = grep { ! $seen{$_}++ } @array; }, });