use strict; use warnings; open(my $in, "<", "input.txt") or die "Cannot open < input.txt: $!"; open(my $out, ">", "output.txt") or die "Cannot open < output.txt: $!"; my ($words, $chars) = (0, 0); while (<$in>) { $chars += length($_); $words += scalar(split(/\s+/, $_)); print $out ("Words=$words\nCharacters=$chars\n"); } #### Words=10 Characters=68 Words=81 Characters=475 Words=116 Characters=684