in reply to Joining multiple lines together while parsing

If you could show some more sample input and especially the expected output (Update: root node has been edited to include that), that would be helpful, for example I'm not sure if you want "Warning bad news here" to appear in the output.

Based on what you've provided, here's one way, using a negative lookahead to prevent the "keywords" from being interpreted as continuations.

use strict; use warnings; use Data::Dumper; local $/ = "\n\n\n"; while (<DATA>) { next unless m/Dumpdata example/; my %row = m/ ^ \s* (\w+:) \s+ ( (?: (?!^\s*\w+:) . )+ ) /xmsg; print Dumper(\%row); } __DATA__ Dumpdata example ----------------- Warning bad news here Detail: Some really nice infos these are Info: This is a problem but there is a solution

Output:

$VAR1 = { 'Detail:' => 'Some really nice infos these are ', 'Info:' => 'This is a problem but there is a solution ' };

Replies are listed 'Best First'.
Re^2: Joining multiple lines together while parsing
by Arengin (Novice) on Mar 24, 2017 at 10:28 UTC
    The output to the example should be:

    "bad news here"; "Some really nice infos these are"; "This is a proble +m but there is a solution"; "2nd of 4"
    Sorry for not posting that, I forgot completly about that.

      In that case, how are continuation lines identified? In other words, how should the program act in the case of the following input?

      Detail: Some really nice infos these are Warning bad news here Detail: Some really nice infos these are Info: This is a problem but there is a solution Warning bad news here is this a continuation or not?
        The input is always like:
        Dumpdata example ----------------- Warning Detail: Info: Spec: Dumpdata example ----------------- Warning Detail: Info: Dumpdata example ----------------- Warning Detail: Spec: Dumpdata example ----------------- Warning Detail: Info: Spec:

        The "Dumpdata example" always starts a new section even if not all elements were present.
        Hi
        That last one works great, but is there a way, to add " to every field at the start and end, so that the values are like "value" so I can use it for csv?
        Works great. thank you very much