You have a foreach
loop inside a while
which will print all of the keys of the %position
hash for every line of input
That will cause symptoms like what you’re describing. Is that what you’re looking for?
solved Double hash entries while printing