in reply to corruption of jpg written and retrieved from sqlite

You may need to binmode your files, especially on Windows. Try open (my $MYFILE,'<:raw', ... and open (my $OUTPUT, '>:raw', ... (which is the equivalent of binmode $filehandle;).

Update: Added a bit more info.