#!/usr/bin/env perl use strict; use warnings; while () { 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 #### path/to/some/file path/to/some/other/file REPLACEMENT path/to/file