Will this work for you?
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This is shorter actually.
RewriteCond %{HTTP_HOST} ^example\.com [NC,OR]
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]