The thread wasn't really about handling "a" vs. "an" correctly, but that's okay. As for your code snippet... apart from forgetting the "$" on the fourth mention of "something", there are some problems...
Since your three "exceptional case" conditions are not anchored to be string-initial, they'll misfire on words like "aunt", "aura", "man-hour", "dishonest", etc. Also, after you fix the anchoring, don't forget that adjectives can occur between the indefinite article and the noun, and many adjectives can begin with "un" as a negative prefix -- e.g. if your code snippet is preceded by:
$something = "untimely death";
you will get Bad English ("a" instead of "an"). In fact, it's pretty hard to handle word-initial "u" -- consider "unanswered" vs. "unanimous", "uninformed" vs. "uniform", etc. (And folks may disagree about cases like "Ugandan", "Ugaritic" and even "Uruguayan".) And then there's all those words starting with "eur"... Unless you take the time to plug in a pronouncing dictionary, you'll just have to put up with some mistakes.
Still, here's a stab that tries to handle most cases in a reasonable way -- note how it sets the initial "u" problem apart as a separate condition, allowing it to be more complicated all by itself. (This code can be run with target words as command-line args, but the subroutine is self-contained and easy to modularize.)
#!/usr/bin/perl
use strict;
sub indef_article
{
local $_ = shift;
my $article;
if ( /^(e)?u(\w+)/i ) {
my $e = $1;
local $_ = $2;
$article = ( $e or /^(?:nanim|ni(?!n)|[gr][aeu])/i ) ? "a" : "
+an";
# assumes y-glide pronunciations for Uruguay, Uganda, etc.
}
else {
$article = ( /^(?:[aeio]|ho(?:ur|nest))/i ) ? "an" : "a";
}
return "$article $_";
}
print indef_article( $_ ).$/ for ( @ARGV );