use strict; my $line = "http://127.0.0.1/home_dir"; if ($line =~ m% # begin regex - alternate delimiter ( # begin Capture #1 http: # protocol ) # end Capture #1 /{2,2} # (discard) exactly two forward slashes # note: no need to escape the "/" now, # can also be written as {2} in some cases ([\d.]{1,14}) # Capture #2, including literal dots IP / # (discard) one forward slash (\w{1,9}) # Capture #3, one-or-more (chars in range a-z OR underline) %x) # end regex, use extended syntax, end the if predicate { print "$1\n"; print "$2\n"; print "$3\n"; } else { print "Bad RegEx\n"; } exit;