>perl -wMstrict -le "my $s = 'oneone'; my $regex = qr/one/; ;; for (1 .. 6) { if ($s =~ /$regex/g) { printf qq{matches '$&' at %d, pos at %d \n}, $-[0], pos $s; } else { print 'no match'; } } " matches 'one' at 0, pos at 3 matches 'one' at 3, pos at 6 no match matches 'one' at 0, pos at 3 matches 'one' at 3, pos at 6 no match