in reply to Solve the large file size issue

When converting oneliners to Perl code, there are two ways. The first is to convert the onliner to a full Perl program:

perl -MO=Deparse -pi.bak -e s/$search(?=,)\/$replace/g

The alternative is to use File::Inplace, which implements the -p-loop as a Perl module.