Your code works for me ...
please check
- the array @dates contains exactly what you expect
- that the hash is empty before you start your counting
- that the last line of output is not due to some print-statement after your code-fragment (*)
hth, Rata
(*) I guess that is the reason for your issue