Scripting >> Perl >> regexp >> How to use non capturing group (?:

$string="http://stackoverflow.com/questions/tagged/regex"; my @groups = ( $string =~ m/(?:http|ftp):\/\/([^\/]*+)\/(.*)/ ); print "with non capturing\n"; foreach $group (@groups) { printf "group : %s\n",$group; } print "\nwithout non capturing\n"; $string="http://stackoverflow.com/questions/tagged/regex"; my @groups = ( $string =~ m/(http|ftp):\/\/([^\/]*+)\/(.*)/ ); foreach $group (@groups) { printf "group : %s\n",$group; } Results: with non capturing group : stackoverflow.com group : questions/tagged/regex without non capturing group : http group : stackoverflow.com group : questions/tagged/regex