use CGI qw(:standard); my $mime_type = 'image/jpeg'; my $size = length($data); # Assuming $data contains your image print header( -type => $mime_type, -Content_Length => $size, ); print $data;