#!perl use Benchmark; my $junk = ' The quick brown fox Jumped over the lazy dog '; timethese(-10, { 'split' => sub { $x = join ' ', split ' ', $junk; }, 'trans' => sub { ($x = $junk) =~ tr/ \t\r\n/ /s; $x =~ s/^ //; $x =~ s/ $//; }, 'subst' => sub { ($x = $junk) =~ s/\s+/ /g; $x =~ s/^ //; $x =~ s/ $//; }, 'subst2' => sub { ($x = $junk) =~ s/^\s+//; $x =~ s/\s+$//; $x =~ s/\s+/ /g; }, });