Here is the entire code to accomplish your task. It will delete 1st & 3rd lines.
use warnings; use strict; my @array; open FH,"data.txt"; @array = <FH>; for my $i (0..$#array) { $array[$i] =~ s/^(\*\/tmp\/dst\/file(1|3)\*(\d){3}\*RW\*(\d){3,4})$/ /; #replace the lines you want to delete with " " (space) } my @result = grep(/[^\s]/,@array); #Take other lines in @result. close FH; open FH,">data.txt"; print FH @result; Hope it is useful. -----Original Message----- From: btna [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2008 9:21 PM To: beginners@perl.org Subject: How to replace one line in a text file with Perl? Hi all, I have a file that looks like: */tmp/dst/file1*234*RW*6790 */tmp/dst/file2*568*RW*908 */tmp/dst/file3*345*RW*746 */test/flm/file4*354*RW*987 */test/flm/file5*643*RW*645 I need to keep all of the lines with the exception of the one with file1 and file3 which have in common "/tmp/dst". I need to preserve the line /tmp/dst/file2 plus the others that start with */test Any ideas on how to do this with perl? Thanks, BTNA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/