You did reasonable job minimizing the code, but the point I was making was that your issue did not require
Tk. If I read a post and see
use Tk; up top, I assume the issue pertains to GUI. As I am not familiar with the intricacies of Tk, I'm likely to skip it without much consideration since I figure there are monks more well suited to aid that OP. In addition, testing your code requires I have Tk installed on my machine, and I'm not going to install Tk just to run the code of an unknown netizen.
In summary, your priorities in creating code to be posted should be first use strict; use warnings;, then the smallest number of dependencies, and finally short but clear code.