To amplify on what Anonymous Monk said, here is how to do it. You do not want to rebuild the $hbox, only the image. I also cleaned up your code, you had many useless lines. The script below will cycle thru all jpg's in the script's directory for the demo. I improved on your use of "cat" to load the file, that code looked familiar to me, and is not very advanced. :-) The code below is much better, and it can be improved a bit, but it does show you the idea.