No they don't. For starters, your split produces and assigns at least three values in every case the pattern matches. The difference in their effects may be irrelevant to your specific application, but that doesn't make them equivalent. Taking that into consideration from the start, you shouldn't have needed to benchmark them to predict the outcome.
If you want a regex version that works meaningfully similar to the split
, it would have to look something like this:
my @a = ($foo =~ /(?:\s+)?(.*?)(?=\s)/g);
(Because your pattern is as simple as \s+
, you can formulate a regex version like
my @a = ($foo =~ /(\S+)/g);
but that doesn't generalize to splitting at foo(?:bar|baz)?
Makeshifts last the longest.