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;