in reply to blob output

I think you confuse the name of the photo with its content, the "blob" as per your title.

1. Does your DB store the filenames (of files which are stored locally) of photos which can be retrieved by ID? Then it is a matter of your perl cgi script to adjust your img src to point to that local filename given the photo ID.

2. Does your DB contain the actual image content as a blob/binary data? Which you want your perl script to retrieve by id and then send over (the actual binary data) all the way to the client's browser and in particular to that img? Then you need something more advance for your src=. Your perl CGI script must send over the image binary data using the appropriate headers Content-type: image/jpeg...

But I will leave you to more expert hands: read this How can I use a CGI script to return an image?

bw, bliako