switch ($j) {
Whoa! Don't.
This code suggests to me that you're using Switch, which is known to introduce random and weird errors into your scripts. The first step is to remove everything related to Switch.
After you've exorcised all usage of Switch from your script, your usage should basically work. Potentially, you need to declare another variable and store the index in it rather than the loop variable:
foreach my $j (0..$i-1) {
my $idx = $j; # make a copy
my $SUB = "${idx}Textfield_MaxText";
*$SUB = sub { variableMaxText( $idx );
};