use warnings; # Great :) use strict; # Also great :) ... # Ok, so here you open the file for INPUT. Great :) open(my $fh, '<', $file) or die "Could not open file: $!"; ... # Ok, so here you show the line to the user, mutatis mutandis. print $line; ... # But where did you open the file for OUTPUT? # And where did you write the line (changed when applicable) to the file? # This code is unnecessary. else { next; } }