Perl - search and replace a particular field

Hi,

I have a file having around 30 records. Each record has 5 fields delimited by PIPE. Few records in the file having Junk characters in the field2 and field4.

I found the junk charcter and I tested it and replace the junk with space with the command below

perl -i -p -e "s/\x00/ /g" <myfile>.

My requirement is I want to replace the Junks in the 2nd field only and should not replace junks in 4th field.

How to do this? Please help!!

Thanks,
Ramkrix

If you want to match the first occurence, remove the g modifier.

perl -i -p -e "s/\x00/ /" <myfile>

BTW, how do your junks look like?