# As suggested by toolic above use strict; use warnings; print "Please enter the file name you want the word count\n\n"; my $file= ; chomp $file; # Lexical file handles (my $fh) are better than file globs. # Also, three-argument open() is better than two-argument open(). open(my $fh, "<", $file) or die $!; my %u_wc; my $words = 0; # Don't forget to declare $word! while (<$fh>){ my @words = split; $words += @words; $u_wc{$_}++ for @words; } # print ("The number of words in the file is $words\n\n"); # The parens are useless here, and also inconsistent with the print statement # that prompted us for a file name. print "The number of words in the file is $words\n\n"; # print ("this are the unique words $u_wc\n\n"); # $u_wc isn't a variable. We do have %u_wc though. print "These are the unique words: ", join(" ", keys %u_wc), "\n\n";