$ perl -Mre=debug -le "$f=123; $f=~/^.*/g; warn pos $f; $f=~ /\d/g; warn pos $f; " Compiling REx "^.*" Final program: 1: BOL (2) 2: STAR (4) 3: REG_ANY (0) 4: END (0) anchored(BOL) minlen 0 Compiling REx "\d" Final program: 1: DIGIT (2) 2: END (0) stclass DIGIT minlen 1 Matching REx "^.*" against "123" 0 <> <123> | 1:BOL(2) 0 <> <123> | 2:STAR(4) REG_ANY can match 3 times out of 2147483647... 3 <123> <> | 4: END(0) Match successful! 3 at -e line 1. Warning: something's wrong at -e line 1. Freeing REx: "^.*" Freeing REx: "\d" $ perl -Mre=debug -le "$f=123; $f=~/^.*/; warn pos $f; $f=~ /\d/; warn pos $f; " Compiling REx "^.*" Final program: 1: BOL (2) 2: STAR (4) 3: REG_ANY (0) 4: END (0) anchored(BOL) minlen 0 Compiling REx "\d" Final program: 1: DIGIT (2) 2: END (0) stclass DIGIT minlen 1 Matching REx "^.*" against "123" 0 <> <123> | 1:BOL(2) 0 <> <123> | 2:STAR(4) REG_ANY can match 3 times out of 2147483647... 3 <123> <> | 4: END(0) Match successful! Warning: something's wrong at -e line 1. Matching REx "\d" against "123" Matching stclass DIGIT against "123" (3 bytes) 0 <> <123> | 1:DIGIT(2) 1 <1> <23> | 2:END(0) Match successful! Warning: something's wrong at -e line 1. Freeing REx: "^.*" Freeing REx: "\d" $