while (<>) { print; if (m/TheLineBefore/){ # read the line to be replaced my $line = <>; # do something with it $line =~ s/1/0/; # print the new version print $line; } } __DATA__ test data more TheLineBefore LocalCompilerPresent=1 more stuff