in reply to Reduce amount of duplicated code

... I'm having difficulties sometimes with data not being parsed correctly and I can't pinpoint it. Usually it works just fine but sometimes unexplainable data gets parsed.

Just a guess, but the  (.+) regex expression might be a source of trouble. The  + quantifier is greedy. See example below. (Otherwise, what 'difficulties' are you having, exactly?)

>perl -wMstrict -le "my $s = 'foo XXX bar YYY foo ZZZ bar'; print $s =~ m{ foo (.+) bar }xmsg; print $s =~ m{ foo (.+?) bar }xmsg; " XXX bar YYY foo ZZZ XXX ZZZ