http://www.perlmonks.org?node_id=668

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

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, you might consider

    while (<>) {
        foreach $word (m/(\w+)/g) {
            # do something with $word here
        }
    }