Perl Performance Considerations

As stated earlier in avoiding regular expressions, it may beneficial to avoid regexes to improve performance. The following code demonstrates five different ways to split a string.

my $data = 'blarg    test';

my @fields = split(' ', $data);
my @fields = split(/s/, $data);
my @fields = ($data =~ m/^(\S+)\s+(\S+)$/);
my @fields = unpack 'A5xA4', $data;

See also: Avoiding regular expressions

Feedback is always welcome! If you'd like to get in touch with me concerning the contents of this article, please use Twitter.