#! /usr/bin/perl use strict; use warnings; use Benchmark; timethese (1000000, { 'substr' => sub { my $string = '123456789B31S'; $string = substr($string,4,(length($string)-6)); }, 'tauli' => sub { my $string = '123456789B31S'; $string = substr($string,4,-2); }, 'regexp' => sub { my $string = '123456789B31S'; $string =~ s/^.{4}(.+).{2}$/$1/; }}); peters@ronin:~/test> perl perl.pl Benchmark: timing 1000000 iterations of regexp, substr, tauli... regexp: 40 wallclock secs (40.02 usr + 0.00 sys = 40.02 CPU) @ 24987.51/s (n=1000000) substr: 7 wallclock secs ( 7.46 usr + 0.00 sys = 7.46 CPU) @ 134048.26/s (n=1000000) tauli: 6 wallclock secs ( 5.19 usr + 0.00 sys = 5.19 CPU) @ 192678.23/s (n=1000000)