Titel Text (A12-3)
3-123.7 Just another text 3-123.8 Some more text
A12.34 Another item B56.78 Yet another item
Another Titel Text (B23-9)
1-22a.b Just another text
2-3cd.e Some more text
W12.34 Another item
Z56.78 Yet another item
####
Titel Text (A12-3);3-123.7 Just another text
Titel Text (A12-3);3-123.8 Some more text
Titel Text (A12-3);A12.34 Another item
Titel Text (A12-3);B56.78 Yet another item
####
use strict;
use warnings;
my $outcome;
my $previous;
while() {
$outcome = "";
chomp;
$_=~ s/\s(\d\-\d\w{2}(\.\w+)?)/\n$1/g;
$_=~ s/\s([A-Z]\d{2}(\.\d+)?)/\n$1/g;
if (/\s?\d\-\d\w{2}(\.\w+)?.+|\s?[A-Z]\d{2}(\.\d+)?.+|\(\w+\-\d+\)$/)
{
if (/\(\w+\-\d+\)$/ ) {
$previous = $_;
}
else {
$outcome = "$previous;$_";
}
$outcome=~s/^\s+$//g;
print "$outcome\n";
}
}
__DATA__
Titel Text (A12-3)
3-123.7 Just another text 3-123.8 Some more text
A12.34 Another item B56.78 Yet another item
Another Titel Text (B23-9)
1-22a.b Just another text
2-3cd.e Some more text
W12.34 Another item
Z56.78 Yet another item
Some trash
Some trash