in reply to Re: Re: Re: Deleting a line out of text file
in thread Deleting a line out of text file

Here's another way, using grep to exclude lines matching the unwanted pattern as they are read in from the file:
... use strict; my $file = 'data_file.txt'; my $bad_pattern = '019'; open my $in_fh, "<$file" or die "can't open $file to read"; my @good_lines = grep { !/$bad_pattern/ } <$in_fh>; close $in_fh; open my $out_fh, ">$file" or die "can't open $file to write"; print $out_fh $_ foreach @good_lines; close $out_fh;