As with a surprising number of similar issues relating to human language, there's already a module on CPAN for this: Lingua::EN::Inflect -- behold:
#!/usr/bin/env perl use strict; use warnings; use Lingua::EN::Inflect 'A'; while (<DATA>) { while ( /\b (an? \s (\w+))/gx ) { my ( $phrase, $word ) = ( $1, $2 ); if ( $phrase eq A( $word )) { print "RIGHT: $phrase\n"; } else { print "WRONG: $phrase\n"; } } } __DATA__ I am a howling maniac in an hospital. It takes a hour to win an honorable mention. Calling him a umpire is a euphemism. This is a united front against a evil empire.
That just shows how to use the module to check for errors. It should be easy to tweak the example a bit so as to fix them.

(updated to fix a typo in the cpan link.)

One more update: a bit more logic is needed to handle various kinds and amounts of punctuation that might occur between the article and the word that follows:

while (<DATA>) { while ( /\b ((an?) \s\W* (\w+))/gx ) { my ( $phrase, $article, $word ) = ( $1, $2, $3 ); my $bigram = "$article $word"; if ( $bigram eq A( $word )) { print "RIGHT: $phrase\n"; } else { print "WRONG: $phrase\n"; } } } __DATA__ Suitable for a (older) child or an 'early adult'.

In reply to Re: Perl pattern matching question by graff
in thread Perl pattern matching question by MadhAric

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.