A Simple CGI Wrapper 

require CGI;

send_phonelist_pdf();

sub send_phonelist_pdf {
  my $cgi = CGI->new;

  my $buf = make_phonelist_pdf();

  print $cgi->header(
          -type => 'application/pdf', -content_length => length($buf)
        ), $buf;
}

sub make_phonelist_pdf {
  # ... same as before except ...

  return $pdf->Finish;
}