#The || ''; part is not needed; could be my $monk2 = shift; my $monk2 = shift || ''; #The $xml && $xml =~ ... is not needed. Also, the regex can #be simplified a bit. How about this: # if($xml =~ m|^(?:ht|f)tp://|) { ... if ($xml && $xml =~ /^(http:\/\/|ftp:\/\/)/) { ... #Just a small thing; if efficiency is a concern you may wish #to try this regex: /^([Ee]|[Mm][Ii])/; /i has some overhead $units = ($units =~ /^(e|mi)/i)? 'mi.': 'km'; ...