#!/usr/bin/perl -w use strict; my @words; open FILE, "<", "input.txt" or die "unable to open input.txt $!"; print "file loaded \n"; while () { @words = split(' ', $_); push @all_words, @words; } foreach $word (@words) { print "$word\n"; } __END__ # if you want to count the words # then that is different - use a hash # table of "word => count" #the default split (/\s+/,$_) #differs only between this special case split(' ',$_) #in how it handles a "null" field at the beginning of the line my %words; while () { my @words = split; foreach my $word (@words) { $words{$word}++; } } === or === my %words; while () { foreach my $word (split) { $words{$word}++; } } ==== or === my %words; while () { $words{$_}++ foreach (split); }