#!/bin/env perl use strict; use warnings; use URI; for my $search ('http://www.foo.com', 'https://www.foo.com', 'www.foo.com', 'WWW.FOO.COM', 'ftp://www.foo.com') { my $url = $search; # we can't modify $search directly $url = 'http://' . $url unless $url =~ m!^\w+://!; # If there isn't a schema, add http:// my $uri = URI->new($url)->canonical->as_string; print "$search => $uri\n"; }