Subroutine will always starts its execution from the beginning(first line) but a co-routine will start from where it left last time.
This is why we say, co-routine has multiple entry points whereas sub-routine has only one.
Yield 'remembers' where the co-routine is so when it is called again it will continue where it left off.
For example:
coroutine foo {
yield 1;
yield 2;
yield 3;
}
print foo();
print foo();
print foo();
Prints: 1 2 3
Note: Coroutines may use a return, and behave just like a subroutine
coroutine foo {
return 1;
return 2; //Dead code
return 3;
}
print foo();
print foo();
print foo();
Prints: 1 1 1
Source - Stack Overflow