#!perl use v5.10; use strict; use warnings; use Benchmark qw(:all); my $results = timethese( 1e6, { repeat => sub{ my $t1 = '20090123'; $t1 =~ /(\d\d\d\d)(\d\d)(\d\d)/; my ($y1,$m1,$d1) = ($1,$2,$3); }, range => sub{ my $t2 = '20090123'; $t2 =~ /(\d{4})(\d{2})(\d{2})/; my ($y2,$m2,$d2) = ($1,$2,$3); }, substr => sub{ my $t2 = '20090123'; my $year =substr ($t2,0,4); my $mon = substr ($t2,4,2); my $day = substr ($t2,6,2); }, chkunpk => sub{ my $t3 = '20090123'; $t3 =~ m/([0-9]{8})/; my ($y3,$m3,$d3) = unpack "A4 A2 A2", $1; }, dirunpk => sub{ my $t3 = '20090123'; my ($y4,$m4,$d4) = unpack "A4 A2 A2", $t3; }, isook => sub{ my $t5 = '20090123'; $t5 =~ /(....)(..)(..)/; my ($y5,$m5,$d5) = ($1,$2,$3); }, } ); cmpthese( $results ) ; __END__ output: Benchmark: timing 1000000 iterations of chkunpk, dirunpk, isook, range, repeat, substr... chkunpk: 4 wallclock secs ( 5.05 usr + 0.00 sys = 5.05 CPU) @ 198137.51/s (n=1000000) dirunpk: 2 wallclock secs ( 3.31 usr + 0.00 sys = 3.31 CPU) @ 301841.23/s (n=1000000) isook: 3 wallclock secs ( 3.08 usr + 0.00 sys = 3.08 CPU) @ 324886.29/s (n=1000000) range: 4 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) @ 309214.59/s (n=1000000) repeat: 4 wallclock secs ( 3.03 usr + 0.00 sys = 3.03 CPU) @ 329924.12/s (n=1000000) substr: 2 wallclock secs ( 1.22 usr + 0.00 sys = 1.22 CPU) @ 820344.54/s (n=1000000) Rate chkunpk dirunpk range isook repeat substr chkunpk 198138/s -- -34% -36% -39% -40% -76% dirunpk 301841/s 52% -- -2% -7% -9% -63% range 309215/s 56% 2% -- -5% -6% -62% isook 324886/s 64% 8% 5% -- -2% -60% repeat 329924/s 67% 9% 7% 2% -- -60% substr 820345/s 314% 172% 165% 153% 149% --