use CGI; my $q = CGI->new; my $imgdata = get_image_data(); print $q->header( 'image/jpeg' ); # or image/gif, etc. print $imgdata;