#!/usr/bin/env perl -l use strict; use warnings; use Benchmark qw{cmpthese}; my @strings = ( 'A B C', 'D E', 'F ', 'G', 'H ', 'I ', "\N{MERCURY} \N{FEMALE SIGN} \N{EARTH}", "\N{MALE SIGN} \N{JUPITER}", "\N{SATURN} ", "\N{URANUS}", "\N{NEPTUNE} ", "\N{PLUTO} ", ); my $re = qr{\s+\b}; cmpthese -1 => { no_re_check_and_split => \&no_re_check_and_split, re_check_and_split => \&re_check_and_split, split_and_re_check => \&split_and_re_check, }; sub no_re_check_and_split { for (@strings) { next if substr($_, -1, 1) eq ' ' or rindex($_, ' ', length() - 2) == -1; my @parts = split /$re/; } } sub re_check_and_split { for (@strings) { next unless /$re/; my @parts = split /$re/; } } sub split_and_re_check { for (@strings) { my @parts = split /$re/; next if @parts > 1; } }