for ( $i = 1; $i <= 5; ++$i ) { push( @array, $i ); print "@array\n"; } while ( @array ) { $firstTotal += pop( @array ); # remove last element print "@array\n"; # display current @array } print "\$firstTotal = $firstTotal\n\n";