use Benchmark; @chars = ('x', ' '); $string = ""; $string .= $chars[rand 2] for (1..1000); timethese( 5000, { 'split' => 'split / /, $string', 'rand_split' => 'rand_split(" ", $string)' }); sub rand_split { my ($sep, $string) = @_; my ($element, $char, $pos, $end, @array); $end = length($string); $element = ""; for ($pos = 0; $pos < $end; $pos++) { $char = substr($string, $pos, 1); if ($char eq $sep) { push (@array, $element); $element = ""; } else { $element = $element . $char; } } push (@array, $element); return (@array); } #### rand_split: 43 wallclock secs (40.37 usr + 0.01 sys = 40.38 CPU) @ 123.83/s (n=5000) split: 4 wallclock secs ( 3.73 usr + 0.00 sys = 3.73 CPU) @ 1342.28/s (n=5000)