perl -pe' if (length > 3) { my @args = split /\|/; # I'm surprised the following line works in a # shell script, with the single quotes and all... if ($args[1] eq '$service' and $args[3] eq '$bundle') { $args[4] =~ s/N/Y/; $_ = join "|", @args; } } ' $inputfile