|Just another Perl shrine
That's the way to do it in Perl, but one note of caution: your initializer isn't being executed before your loop. The declaration and sub definition happen at compile time, but the assignment is a runtime thing, and the code gets run from top to bottom. Your output is unchanged even if you initialize $memory to 'a' (which the autoincrement op should then change to b and c in turn).
You can make your enclosing block a BEGIN block, or you can put it above the rest of your code.
Caution: Contents may have been coded under pressure.