I see three cases to deal with:
- The first sentence, which has no preceding punctuation-whitespace.
- A "regular" sentence that has the punctuation-whitespace-word sequence.
- A regular sentence that happens to start on a new line.
Assuming the file is not so huge that we can't slurp it in I'd take the easy way out of number three and undef the input record separator (
undef $/;). The first two could be handled separately
#!/usr/bin/perl -w
use strict;
@ARGV = '/Perl/LearningPerl/Test';
local $/ = '';
for(<>) {
if(/^([a-z]+)/) {
print "\'$1\' is not capitalized\n";
}
while(/[:.?!]\s+([a-z]\w*)/g){
print "\'$1\' is not capitalized\n";
}
}