use strict; use warnings; use Text::ParseWords; while (my $line = ) { my @fields = quotewords(',', 0, $line); for my $field (0 .. $#fields) { print $field + 1, " $fields[$field]\n"; } } __DATA__ "earth",1,,"moon",9.374 "mars",2,,"phobos",,"deimos", #### 14:17 >perl 1671_SoPW.pl 1 earth 2 1 3 4 moon 5 9.374 1 mars 2 2 3 4 phobos 5 6 deimos 7 14:20 >