in reply to image encode base64 - help needed

If those two snippets in the OP are in the same script, you can add a few more lines to use MD5 checksums on $raw_string and $decoded, to confirm whether the encode/decode is behaving as it should:
use strict; use warnings; use MIME::Base64; use Digest::MD5 'md5_hex'; open (my $image, 'Z:\capture.png') or die "$!"; binmode $image; my $raw_string = do{ local $/ = undef; <$image>; }; my $encoded = encode_base64( $raw_string ); my $decoded = MIME::Base64::decode_base64($encoded); my $rawmd5 = md5_hex( $raw_string ); my $decmd5 = md5_hex( $decoded ); warn sprintf( "raw != decoded (%s vs %s)\n", $rawmd5, $decmd5 ) if ( $rawmd5 ne $decmd5 ); open my $fho, '>', 'Z:\photo.png' or die $!; binmode $fho; print $fho $decoded;
(I added binmode on the input file handle, just in case; but if that's the problem with the OP code, then I wouldn't expect your input and output files to be exactly the same size.)