#! perl -sw use strict; use Benchmark; my @i = qw( a b c x d e f a g h i j k l z m n o p q r t s t b u v w x y z ); my @dups = qw( x a z t b ); my $index = 13; my @items = @i; sub remove_item { my %del = map { $_ => 1 } @_; my @part_1 = grep { !exists $del{$_} } @items[0..$index]; my @part_2 = grep { !exists $del{$_} } @items[$index+1..$#items]; $index = $#part_1; @items = (@part_1, @part_2); } sub remove_items { my ($i, %del) = (0); @del{@_} = undef; @items = grep { $i++ and !exists $del{$_} and $index -= ($i < $index) } @items; } print "@dups\n"; @items = @i; $index = 13; print "$index: $items[$index] : @items\n"; remove_item @dups; print "$index: $items[$index] : @items\n"; print $/ x 2; print "@dups\n"; @items = @i; $index=13; print "$index: $items[$index] : @items\n"; remove_item @dups; print "$index: $items[$index] : @items\n"; print $/ x 2; Benchmark::cmpthese( 1000, { mine => sub { @items = @i; $index=13; remove_items @dups; }, yours => sub { @items = @i; $index=13; remove_item @dups; }, }); __DATA__ # Output C:\test>195796 x a z t b 13: l : a b c x d e f a g h i j k l z m n o p q r t s t b u v w x y z 9: l : c d e f g h i j k l m n o p q r s u v w y x a z t b 13: l : a b c x d e f a g h i j k l z m n o p q r t s t b u v w x y z 9: l : c d e f g h i j k l m n o p q r s u v w y Benchmark: timing 1000 iterations of mine, yours... mine: 0 wallclock secs ( 0.51 usr + 0.00 sys = 0.51 CPU) @ 1960.78/s (n=1000) yours: 1 wallclock secs ( 0.64 usr + 0.00 sys = 0.64 CPU) @ 1562.50/s (n=1000) Rate yours mine yours 1562/s -- -20% mine 1961/s 25% -- C:\test>