This is not a trivial task to do in perl. However there are other tools, for example khtml2png, which uses the khtml rendering engine (the one that is used in the browser Konqueror, and I think it has some common code with webkit; not sure though).
You can also search for thumbshot, I'm sure there are other solutions out there.