in reply to How to use 'last' / 'next' commands to exit loop?

last exit the current loop ( in your case the while loop ). if you like to exit all loops and continue at with the next entry on the for loop lable that.
... loop: foreach ( @arr_vars ){ while( (my $key, my $value) = each %mapped_vars){ ... if ( $_ eq $key ) { ... next loop; } }
Boris