in reply to whats wrong with this break ?

Making the cpu break out of the loop at the point you want it to is the easy part. The harder part is making the code simple to understand 6 months from now, when you're in a hurry with a boss breathing down your neck, after a night of heavy drinking.

The quick-and-easy-solution™ is to use labels so it's clear which component you're exiting, and why.

HEADER: while (<STDIN>) { print "--> $_"; last HEADER if /^2/; print "--> $_"; }

I'll also mention that I'm not fond of $_, except in the shortest of scripts. If you need to nest the loops, you have to use real variables. If you call routines, $_ may or may not be trampled. I find it simpler and easier to assign to variables from the start, and it improves clarity at the cost of a few characters. And notice that your desire to have the leading arrow forced you to have $_ in the print statement, rather than the supposedly economical print;.

HEADER: while (my $line = <STDIN>) { print "--> $line"; last HEADER if '2' eq substr $line, 0, 1; print "--> $line"; }

But if you refactor this chunk into a subroutine, it suddenly becomes a bit of documentation!

process_file_header(); process_file_participants_list(); process_file_contract_details();

Using subroutines rather than linear code ss especially useful if your document is not a linear flow but has components that can appear multiple times in random order. Of course, in the extreme case, you're writing an XML parser or re-inventing Expect. Challenges are good for the soul.

given (determine_context()) { when ( $FOO ) { process_foo(); } when ( $BAR ) { its_a_bar(); } when ( $BAZ ) { woo_ha(); } default { confused(); } }

As Occam said: Entia non sunt multiplicanda praeter necessitatem.