while(<>) {
  foreach $word (split) {
    $total{$word}++;
  }
}

foreach $word (sort keys %total) {
  print "$word $total{$word}\n"
}
