#!/usr/bin/perl -w use strict; use Benchmark; my $count = 500000; my $line = "1!2!3!4!5!6!7!8!9"; my @arr = split /!/, $line; my @exclude = (2,5..8); my @exclude_lkup; $exclude_lkup[$_] = 1 for @exclude; sub ikegami { my @tarr = @arr; my @filtered = map $tarr[$_], grep !$exclude_lkup[$_], 0..$#tarr; } sub injun { my @tarr = @arr; @tarr[@exclude] = (); @tarr = grep $_, @tarr; } timethese ( $count, {'Ikegami' => '&ikegami', 'InjunJoel' => '&injun'} ); #### Benchmark: timing 500000 iterations of Ikegami, InjunJoel... Ikegami: 16 wallclock secs (15.88 usr + 0.00 sys = 15.88 CPU) @ 31494.08/s (n=500000) InjunJoel: 10 wallclock secs ( 11.05 usr + 0.00 sys = 11.05 CPU) @ 45265.25/s (n=500000)