#!perl use strict; use CGI qw(:standard); use DBI; my $id = param('id'); my $dbh = get_dbh(); my $sql = "SELECT bin FROM software_repos WHERE id=?"; my ($pdf) = $dbh->selectrow_array($sql,undef,$id); print header('application/pdf'), binmode(STDOUT); print $pdf; # whatever you need to get a connection sub get_dbh{}