in reply to s/\w/random character/g

First off, if you want the replacement part of a substitution operation interpreted as perl code, use the /e switch. Second, if you have a reference to a subroutine, use $ref->() to call it.

Third, don't use integer numbers for ASCII characters -- just use the characters instead.

Check this out:

use strict; use warnings; my @CHARS = ('A'..'Z', 'a'..'z'); sub rand_char { return $CHARS[rand @CHARS]; } while (<DATA>) { s/\w/rand_char()/eg; print $_; } __DATA__ ABCDEFG