If you want to follow a simple scalar variable with a left square
bracket, you need to delimit the square bracket so that it
isn't considered part of an array reference, as follows:
@fred = qw(eating rocks is wrong);
$fred = "right"; # we are trying to say "this is right[3]"
print "this is $fred[3]\n"; # prints "wrong" using $fred[3]
print "this is ${fred}[3]\n"; # prints "right" (protected by braces)
print "this is $fred"."[3]\n"; # right again (different string)
print "this is $fred\[3]\n"; # right again (backslash hides it)
 |  |  |
3.4. List Assignment |  | 3.6. The foreach Control Structure |