in reply to Replacing an entire line if a substring is found

G'day victorz22,

When you simply want to test for a substring, use index: you'll find it's measurably faster than a regex. [You can use Benchmark to measure it.]

Here's the technique you need:

#!/usr/bin/env perl use strict; use warnings; while (<DATA>) { print index($_, 'SUBSTR') > -1 ? "REPLACEMENT\n" : $_; } __DATA__ path/to/some/file path/to/some/other/file path/to/SUBTSTRING/file #replace entire line if SUBSTRING is found path/to/file

Output:

path/to/some/file path/to/some/other/file REPLACEMENT path/to/file

— Ken