if your whole file is read at once, it is most likely that some part of your program modify the $/ var.
$/ The input record separator, newline by default.
Read the whole story with perldoc perlvar
Thanks for the idea. But I have just double checked the whole script if it accidentally messes with $/ but it doesn't.
The same code is behaving as it should as long as the mark $marke==0, but this makes no sense to me.