In addition to my esteemed brother's previous comment, I might suggest that you got the idea for
my $x[0] from the idiom of
local $x[0]. However,
local is very very different from
my, and you can't generally assume that either one can replace the other in any situation.
BTW, the local operator is so confusingly named that Larry is renaming it to temp in Perl 6. And there was much rejoicing!
-- Chip Salzenberg, Free-Floating Agent of Chaos