#!/usr/local/bin/perl -w use strict; use Benchmark; my $testlarge = "a " x 100000; my $testsmall = "a b c d e f"; timethese(-10,{ One => sub { my ($y) = (split(/\s+/,$testlarge))[0]; }, Two => sub { my ($y) = (split(/\s+/,$testsmall))[0]; }, Three => sub { my $y = ( $testsmall =~ (/([^\s]*)\s+/g))[0]; }, Four => sub { my $y = ( $testlarge =~ (/([^\s]*)\s+/g))[0]; }, }); mik@mach5:/home/mik/monk)./benchthis.pl Benchmark: running Four, One, Three, Two, each for at least 10 CPU seconds... Four: 19 wallclock secs (18.38 usr + 0.02 sys = 18.40 CPU) @ 1.14/s (n=21) One: 13 wallclock secs (12.72 usr + 0.00 sys = 12.72 CPU) @ 2.12/s (n=27) Three: 12 wallclock secs (10.28 usr + 0.00 sys = 10.28 CPU) @ 12748.55/s (n=131071) Two: 11 wallclock secs (10.00 usr + 0.00 sys = 10.00 CPU) @ 18600.60/s (n=186006)