This is fairly similar to the linked possible duplicate, but since that one forces www
where you want to remove it, it might warrant a separate answer.
Try something like this:
RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{HTTPS}s ^on(s)|off
RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$
RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L]