On button click->add timer to do subroutine A. sub A() { if(socket != EOF) { open socket, read line. } else { kill timer. } }