http://www.perlmonks.org/?node_id=975036, which does not show a working solution, suggests this can be done by writing and updating a temp file and using a timeout to periodically clear and reload the image from there.
Leaving aside the feeling that a temp file is a kludge, where does this timeout go? In or outside the main loop?