use strict; use warnings; my $line = ; while() { if(/^sb1 1.0 142r$/) { print substr($line, 0, -13) . "\n"; } else { print $line; } $line = $_; } print $line; __DATA__ lines before the changed section 4.62399E+09 2.90871E+09 7.17338E+14 sb1 1.0 142r lines after the changed section another instance of the lines to be changed 4.62399E+09 2.90871E+09 7.17338E+14 sb1 1.0 142r another line with 7.17338E+14 in it the rest of the file #### lines before the changed section 4.62399E+09 2.90871E+09 sb1 1.0 142r lines after the changed section another instance of the lines to be changed 4.62399E+09 2.90871E+09 sb1 1.0 142r another line with 7.17338E+14 in it the rest of the file