The input data looks kinda like this ___DATA___ path/to/some/file path/to/some/other/file path/to/SUBTSTRING/file #replace entire line if SUBSTRING is found path/to/file #### sub scanForSubstringReplaceLine{ my($inputText, $subStringToScan, $lineReplacement) = @_; my $replacedText; $inputText =~ s/$subStringToScan/$lineReplacement/g; $replacedText = $inputText; return $replacedText; }