http://www.perlmonks.org?node_id=1031028

zBernie has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to split a space separated log file, and found that occasionally, the third column (FROM) is comprised of multiple strings. E.g., Marco's Pizza. Sometimes the FROM column has 2 or 3 tokens. So the split command below does not always work. Is there a way to handle this split with the varying number of tokens in the FROM column?

my ($reqid, $dest, $from, $date, $time, $pages, $rcv) = split(/\s+/, $ +_); REQID DEST FROM DATE TIME nPa +ges RCV 138454 mail_room Marco's Pizza 12/26 21:52 1 rcv 138446 custsvc 973 618 0577 12/26 18:44 1 rcv 138445 county2 spam 12/26 18:41 3 rcv 138444 custsvc spam 12/26 18:30 1 rcv 138439 county2 7182737253 12/26 17:54 2 rcv 138438 county2 Acme Products, Inc. 12/26 17:52 1 rcv