Use the split function:
while (<>) {
foreach $word ( split ) {
# do something with $word here
}
}Note that this isn't really a word in the English sense; it's just
chunks of consecutive non-whitespace characters.
To work with only alphanumeric sequences (including underscores), you might consider
while (<>) {
foreach $word (m/(\w+)/g) {
# do something with $word here
}
}