When running your code, I am not getting the error. Are you sure you posted exactly the code that produced the error?
BTW, you should
use warnings. They will tell you that
$readcounter is used only once (you probably wanted
$readcounter++? It does not apease the warning, but works.)