#!/usr/bin/perl use warnings; use strict; use feature qw( say ); use Getopt::Long; # Create a script that accepts one or more files specified on the command-line and count the number of times letters appeared in the files. my @file; GetOptions ( "file=s" => \@file, ); usage() unless (@file); my $href = {}; # hash ref to hold results foreach (@file) { # Iterate over all the user supplied files open (my $fh, '<', $_) or do { warn "Can not open $_: $!"; next; }; # If we can't open the file warn and move on while (<$fh>) { # Iterate over lines in the file my $line = lc($_); # Convert chars to lower case $href->{$_} += () = $line =~ /$_/g foreach ('a' .. 'z'); # Populate results hosh with letter counts } close $fh; } # Print out the occurance of letters a .. z say "$_: $href->{$_}" foreach ('a' .. 'z'); sub usage { print <