#!/usr/bin/perl -w use strict; # in addition to using -w this will # help you find more errors # if you use strict then you have to declare your variables, usually using my my %count = ("para",0,"sen",0); while ( <> ) # read a record (a line here) and set $_ { # a paragraph is any line that has at least one non-space character if ( /\S/ ) { $count{para}++; } # the g modifier allows you to loop through the string # matching successive occurences of the pattern while ( /[.?!]/g) { $count{sen}++; } # use s/// to substitute the pattern # \w is a word character, # $1 is the text that was matched between the () # /g does the substitution for all matches in the string # /e evaluates the right part expression lc($1) s/([aeiou]\w*)/lc($1)/eig; } # this is how you print a hash foreach my $value (keys %count) { print "$value: $count{$value}\n"; }