i agree with
jdtoronto's and
davorg's
split suggestion ...
Another posibility (especially if there can be escaped delimiters) is to use one of the
CSV modules to parse it.
If you really wanted to fix the regex (i suspect that would be less efficient and less readable than
split), something like:
$idx =~ s/^((?:[^|]*\|){15}[^|]*)STOCK/$1BOXXE/;
It's also possible (obviously relies on assumptions) for you to get away with just dropping the
/g modifier .. then it would only break if "STOCK" also appeared in columns 1-15 somewhere, but would not break if it was in column 17+.