while () { next if ! /^DATA/; # ... #### for 1 .. 3; while () { # ... #### my $found_start_of_data; while () { last if $found_start_of_data; # ... some complex code that sets the flag } while () { # ... } #### # Extract my ($want) = $data =~ m{(some_regular_expression)}; # Eliminate $data =~ s{some_regular_expression}{};