In effect you don't. The query goes to the server and new HTML is sent to the browser. In its simplest form you just use the same HTML code in a print here with variables swopped for your result.
print <<"HERE";
<html>
$result
</html>
HERE
If your images are exactly the same as the query page this will load very quickly.
If you want to have code load into exactly the same web page without a trip back to the server you could load an external Javascript file into the browser cache formatted as a Hash of arrays. This will stay in the browser cache and when queried by Javascript returns results almost instantaneously. The downside is the fact that the data has to be in the browser cache before it starts working.
Best wishes
Sid