http://www.perlmonks.org?node_id=1148066

OldChamp has asked for the wisdom of the Perl Monks concerning the following question:

Sorry for obviously not describing my problem clear enough, so here is the updated Question.

I can use perl 5.010 and there is no problem in reading the complete inputfile in memory.

I have text in a file of the following form, where the dots stands for a random amount of other text. After reading the input-file, all the newline characters are removed and my text is in $line.

.....P1p1/6P1/7P/5PK1/8 w - - 4 34"] {Weiß am Zug} * ..... 1n5P/1P4PK/1q6 b - - 2 42"] {Weiß am Zug} * ..... .......5K2/3R4 w - - 1 33"] {Weiß am Zug} * .....

If I have a space, followed by the letter b, followed by another space, as shown here in the third line, I want to substitute only the following 'Weiss' with 'Schwarz' and then continue to go through the text until there is another occurence of the pattern (space, followed by the letter b, followed by another space), when the next substition should follow.

So the core of the problem is: If I find a certain pattern-1 in the text, then go on till I find a certain pattern-2 and substitute this with a pattern-3. Do this again for the whole text. I have tried the following:

my $line = do { local $/; <>; }; $line =~ s/\n/ /g; # if ( $line =~ m/\sb\s/ ) # { # $line =~ s/Weiss/Schwarz/g; # } $line =~ s/(?<=\sb\s)Weiß/Schwarz/g; ... print $line;

but neither of this gives me the desired result, the text didn't change. How to solve this problem?