Regular Expressions
Split with Regex
split can use a regex separator to break text into fields.
Split with Regex
split_regex.pl
use strict;
use warnings;
my $line = ;
my @words = split /\s+/, $line;
my $first = $words[0];
my $count = scalar @words;
print "line=$line\n";
print "first=$first\n";
print "count=$count\n";
use strict;
use warnings;
my $line = ;
my @words = split /\s+/, $line;
my $first = $words[0];
my $count = scalar @words;
print "line=$line\n";
print "first=$first\n";
print "count=$count\n";
use strict;
use warnings;
my $line = ;
my @words = split /\s+/, $line;
my $first = $words[0];
my $count = scalar @words;
print "line=$line\n";
print "first=$first\n";
print "count=$count\n";
split
A split turns one string into fields wherever the separator pattern matches.