in reply to accessing variable vaule outside for loop

Do you know what  @foo = $bar does?

Let's try it

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; my @foo = 1..3; dd\@foo; @foo = 7..9; dd\@foo; @foo = 4; dd\@foo; @foo = 2; dd\@foo; @foo = ( 4, @foo ); dd\@foo; __END__ [1, 2, 3] [7, 8, 9] [4] [2] [4, 2]

Do you get the problem now ?

perlintro#Arrays shows/links some interesting functions like reverse, and http://perldoc.perl.org/index-functions-by-cat.html#Functions-for-real-@ARRAYs lists some more, as do various Tutorials/manuals in Data Type: Array

$ perl beans Global symbol "$index" requires explicit package name at beans line 11 +. Execution of beans aborted due to compilation errors.

Whoops, looks like you need to clean your room better :)