my ($word1, $word2) = split(/\s+/); if defined($word2) { ... } #### foreach $word (split /\s+/) { ... }