#!/usr/bin/perl use strict; use warnings; open (my $fh, '<', '') or die "Open failed : $!"; undef($/); my %word; while (<$fh>) { my @array = split(/\s+/, $_); foreach (@array) { print "$_\n"; } for (@array){ s/\W//g; tr/A-Z/a-z/; $word{$_}++; } } for (sort(keys %word)) { print "$_ occurred $word{$_} times\n"; }