http://www.perlmonks.org?node_id=3593


in reply to Pig Latin

It depends on how general you want to be. My first run attempt is:

while(<>) { s{ \b([bcdfghjklmpqrstvwxyz]?)(\w+) } { if($1) {$2.$1.'ay'} else {$2."way"} }egix; print; }

The problem is that this doesn't correctly treat cases like th, sh, pr, etc. where there's really a compound starting consonant. Maybe, this would be a bit more correct:

while(<>) { s{ \b([bcdfghjklmpqrstvwxyz]*)([aeiou]+)(\w*) } { if($1) {$2.$3.$1.'ay'} else {$2.$3."way"} }egix; print; }