Have you noticed that if you duplicate the last line (the line with "print"), you'll get two different results? First, it prints 69, which seems correct, but then it prints 138.
This is because you don't use strict. Especially you should write "my $k" to solve this issue.