sub next_foo { while (<>) { return $. if /^FOO:/ } } while (next_foo) { do_something # with $_ }