A few points unrelated to your immediate problem:
- A favourite mantra here: Always use strictures (use strict; use warnings; - see The strictures, according to Seuss).
- Most Perl functions are generally written without parenthesis: push @stack1, "Perl" for example.
- If you simply want to iterate some number of times use for (1 .. @stack1) {...}. Perl uses internal magic to optimise the loop and as it happens, it resolves your issue. The optimisation is generally unimportant. The clarity of intent and correct behaviour are compelling.
Minor variations on the line:
$var = pop (@stack1) + pop (@stack1);
will surprise you one day. It is not defined in what order the pops are executed. If the operator were / or . then the result may be quite different than you expected! The same issue occurs in the evaluation order of parameter lists and can cause very subtle bugs.
Perl reduces
RSI - it saves typing