$a="a "; while ( $a =~ m/$regexp/ ) { # or m//g, m//gc, ... print "a(".$1.")(".$2.")\n"; }