in reply to regexp help -- word boundaries

Not the prettiest, but this should work:

$n =~ s/(?:^|([ ]))$a(?:([ ])|$)/($1 ? $1 : "") . $b . ($2 ? $2 : "" +)/ie;
Warning: Code is untested; note the use of "should" vs. "will".