#!/usr/bin/perl -w use strict; use CGI qw/:standard/; use DBI; my $dbh = DBI->connect("DBI:mysql:database", "user", "password", {RaiseError => 1}); my $sth = $dbh->prepare("SELECT img FROM table WHERE id = ?"); $sth->execute(param('id')); my $img = $sth->fetchrow_arrayref; print header("image/jpeg"), $img->[0];