I wanted to quickly input here. I've been using this, especially where I have apps that run on both http:// and https://
In my case where I use OOP it's usually a subroutine in the main package, but this works just as well, calling the $page_url variable.
Some smart concatenation, no additional modules, strictly native...
Already shows a problem with this sort of approach (copying and pasting the “same” snippet around). I don’t doubt you have it right somewhere but that above is a bug (you need eq and you should probably also normalize case with lc). It will always say the URL is https as is.
String concatenation is, to me, code smell. The “no additional modules” shtick can be paraphrased to: no help from experts who have been solving and testing this exact problem against edge cases for 20 years and will continue to do so as the standards are updated.