my $jpeg = $binary_data; substr($jpeg, 0, index($jpeg, "\xFF\xD8") - 1) = ""; substr($jpeg, index($jpeg, "\xFF\xD9") + 1) = "";