in reply to Re^3: Generalising string in pattern
in thread Generalising string in pattern

An alternate to option 2, slightly faster:
use strict; use Benchmark qw/cmpthese/; my $p = 'stringwithnospacesinit'; my ($a,$b); cmpthese( -5, { a => sub{ $a = $p; $a =~ s/(.)/$1\\s*/g; }, b => sub{ $b = $p; $b = join('\s*',split(//,$b)); }, } ); __END__ Rate a b a 62530/s -- -20% b 78403/s 25% --
update - typo fix

Replies are listed 'Best First'.
Re^5: Generalising string in pattern
by shmem (Chancellor) on Nov 13, 2009 at 15:31 UTC

    ... and add a leading and/or trailing \s* ;-)

    (update: only needed if the pattern is anchored)