in reply to pipe delimited file problem

To expand on imp's suggestion with look-behind assertions, you could use look-behind and look-ahead assertions in combination so that you find a point that is preceded by a pipe symbol or the beginning of the line and followed by a pipe symbol or the newline and do the substitution there. Look-behinds have to be fixed width, hence the alternation of two of them. I have set up a variable $litPipe to hold a literal pipe symbol to avoid a lot of escaping inside the regular expression.

use strict; use warnings; my $litPipe = q{\|}; my $rxBetween = qr {(?x) (?: (?<=\A) | (?<=$litPipe) ) (?=$litPipe|\n) }; while (<DATA>) { s{$rxBetween}{EMPTY}g; print; } __END__ a|b|c|d|e f||h|i|j |l|m|n|o ||||t u|v|w|x|

Here's the output

a|b|c|d|e f|EMPTY|h|i|j EMPTY|l|m|n|o EMPTY|EMPTY|EMPTY|EMPTY|t u|v|w|x|EMPTY

Because the regular expression pins down exactly where you want to do the substitution it copes well with beginning and end of line situations.

I hope this is of use.

Cheers,

JohnGG