perl -E 'local $_ = "foo"; say "Start" if /\G foo/gcx; say pos; say "Mid" if /\G .*/gcx; say pos; say "End" if /\G \z/gcx; say "At End" if pos == length' Start 3 Mid 3 At End