#!usr/bin/perl -w use strict; use constant LEN => 3; use Benchmark qw(:all); my $str; my $count = -2; my $re = timethese( $count, { substring => sub { my $offset = 0; my $length = LEN; while ( $_ = substr $ARGV[0], $offset, $length ) { last if length != LEN; $str .= $_ . $/; $offset += $length; } }, regex => sub { $str .= $1 . $/ while ( $ARGV[0] =~ m/(.{3})/g ); } } ); cmpthese($re);