#!/perl/bin/perl use strict; use warnings; use Data::Dumper; my($ifh, @all_lines); open($ifh, "text.txt") or die "Could not read file.\n"; while (<$ifh>) { # split's default delimiter is whitespace, and if # no expression is supplied, it splits $_ my @lineinfo = split; for (@lineinfo) { # print each element on it's own line print $_, "\n"; } print "\n"; print sprintf qq(Line %d has %d elements.\n\n), $., $#lineinfo + 1; # push a reference to each array into an array push (@all_lines, \@lineinfo); } close $ifh; # Dump it all out... print Dumper(\@all_lines); __DATA__ one two three four five six seven eight nine ten eleven twelve