rewrite skip_prefix() as loop