#!/usr/bin/perl use 5.010_000; use warnings; use strict; my %number_of; my @words; while ( my $line = ) { $number_of{lines}++; $number_of{chars} += length $line; push @words, map { lc } split /[\s.,]+/, $line; } $number_of{words} = scalar @words; foreach my $item (qw(chars words lines)) { say "Number of $item: $number_of{$item}"; } say @words; __DATA__ Hey, diddle, diddle, The cat and the fiddle, The cow jumped over the moon. #### Number of chars: 75 Number of words: 14 Number of lines: 3 heydiddlediddlethecatandthefiddlethecowjumpedoverthemoon #### push @words, map { lc } # change to lower case map { tr/'//d; $_ } # remove apostrophes split /[\s.,?!"]+/, # split on space and punctuation $line; #### use List::Util;