I did try to use Devel::Size to see if the memory actually goes down so am writing the size of the has to a log file every time I "dump" a line and the size never decreases since I have been testing it.
The here is an example. First column is line count into the file being processed, the second is the index (equivalent to $vals1) and the last the size of the %pairs hash. Here the size is 122MB for the %pairs hash ...
...
424872: e5c651161 (122480629)
424875: 6d6148148 (122481928)
424886: 108038067 (122484667)
424890: 4db238067 (122487257)
424892: 502c57487 (122488556)
424895: c53c57539 (122489855)
424896: 578757487 (122489855)
424923: 300959147 (122495178)
424928: a9bb41168 (122496165)
424936: dfc243245 (122499555)
424937: 0a9534098 (122499555)
424944: 666b34098 (122501654)
424954: 494949982 (122504073)
424956: 182939296 (122505372)
424960: c1ad46207 (122507962)
424962: 3d1249982 (122507962)
424968: 3c1336561 (122512355)
424974: b24939296 (122514993)
424987: 3c7b36561 (122517700)
424998: eb1544993 (122520311)
425005: 818a49369 (122521727)
...