http://www.perlmonks.org?node_id=521037


in reply to Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell

$tok =~ /-?\d+/ only checks whether the token contains an integer, so the token can be an integer and some junk before and after it. If I were you, I'd either use anchors like $tok =~ /^-?\d+$/ or at least use only the integer-looking part: if ($tok =~ /(-?\d+)/) { push @stack, $1; ...