my $foo="regexp"; my @matches = $foo =~ /(re)ge(xp)/; #and my $regex=qr{(re)ge(xp)}; my @matches = $foo =~ $regex; #### > perl -we'use strict;use P; my $regex=qr{(re)ge(xp)}; my @matches0 = "regexpregexp" =~ /(re)ge(xp)/g; my @matches = "regexpregexp" =~ $regex; my @matches1 = "regexpregexp" =~ /$regex/g; P "matches=%s, 0=%s, 1=%s", \@matches, \@matches0, \@matches1; ' matches=["re", "xp"], 0=["re", "xp", "re", "xp"], 1=["re", "xp", "re", "xp"]