use strict; my @a = ( 0,1,2,3 ) ; my @b = ( 1,2,3,4 ); my @x = ( 0,1,2,3 ) ; my @y = ( 1,2,3,4 ); my @r = reverse @a; my $next = 0 ; my $first = 0; my $first = shift @a ; print "a $#a shift ",$first,"->"; while ( $next = shift @a ) { print ",",$next } print "\n"; $first = shift @b ; print "b $#b shift ",$first,"->"; while ( $next = shift @b ) { print ",",$next } print "\n"; $first = pop @x ; print "x $#x pop ",$first,"->"; while ( $next = pop @x ) { print ",",$next } print "\n"; $first = pop @y ; print "y $#y pop ",$first,"->"; while ( $next = pop @y ) { print ",",$next } print "\n"; $first = pop @r ; print "r $#r pop ",$first,"->"; while ( $next = pop @r ) { print ",",$next } print "\n"; Gives --- >>>>> See line starting x $ perl test.pl a 2 shift 0->,1,2,3 b 2 shift 1->,2,3,4 x 2 pop 3->,2,1 y 2 pop 4->,3,2,1 r 2 pop 0->,1,2,3