use strict; my $line = "http://127.0.0.1/home_dir"; if ($line =~ / # begin regex ( # begin Capture #1 http: # protocol ) # end Capture #1 \/+ # (discard) one (or more) forward slashes; imprecise (127\.0\.0\.1) # Capture #2, including the dots IP \/ # (discard) one forward slash (home_dir) # Capture #3 (literal and simplistic) /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; #### http: 127.0.0.1 home_dir #### 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;