# since this is messy and we need to use it a bunch of times, let's load it into a scalar. my $val = "[a-z0-9?]+=\-%"; # there is no way in heck this is correct; it's a *beginning* though # get input if (is_url($string)) { # do something with it } ... sub is_url { my $input = shift; $input =~ #(?:http(?:s)|ftp)://$val+\.$val+#i; }