#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] || 'foo.txt'; open (INPUT, '<', $file) or die "Unable to open $file for reading : $!"; my %word; while ( ) { chomp; $word{$_}++ for split " "; } print "$_ : $word{$_}\n" for sort { $word{$b} <=> $word{$a} } keys %word;