in reply to How to split line with varying number of tokens?

Another alternative is based on the fact that your data is nicely vertically aligned, even if not perfect. So you could specify which columns of characters belong to which field. This is something that Excel would also offer when importing such data.

use strict; use warnings; my %format = (#field from to reqid => [ 0, 7], dest => [ 8, 19], from => [ 20, 41], date => [ 42, 48], time => [ 49, 55], npages => [ 56, 59], rcv => [ 60, 70], ); <DATA>; while(<DATA>){ chomp; my %line; for my $item (keys %format) { $line{$item} = substr $_, $format{$item}->[0], $format{$item}->[1] +-$format{$item}->[0]+1; $line{$item} =~ s/^\s*//; # remove leading spaces $line{$item} =~ s/\s*$//; # remove trailing spaces print "$item=$line{$item}, "; } print "\n"; } __DATA__ 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