Gossamer Forum
Home : General : Perl Programming :

Pattern Matching

Quote Reply
Pattern Matching
Let's say that:

$a = 'ABC variable stuff here XYZ more variable stuff here XYZ more variable stuff here';

and I wish to replace the variable information between each ABC and XYZ. How do I do that.

What I tried was $a =~ s/ABC(.*)XYZ/ABC new stuff here XYZ/g; but that replaces from the first instance of ABC through the last instance of XYZ in one pass ... in other words I get ...

$a then equals ABC new stuff XYZ instead of
$a = ABC new stuff XYZ ABC new stuff XYZ etc.

I hope this makes sense to someone.

Thanks for any help.

Lee