in reply to Delete specific lines from txt file.

You are dealing with a database, but making hard work of it. However Perl's DBI module along with DBD::CSV can turn your text based database file into something you can deal with as a "real" database. Consider:

use warnings; use strict; use DBI; unlink 'sports.csv'; my $dbh = DBI->connect("dbi:CSV:f_ext=.csv") or die "Cannot connect: $DBI::errstr\n"; $dbh->do("CREATE TABLE sports (name TEXT, sport TEXT)"); my $sth = $dbh->prepare("INSERT INTO sports (name, sport) VALUES (?, ? +)"); $sth->execute_array({}, [qw(fred joe bob)], [qw(golf hockey luge)]); dumpTable($dbh); $dbh->do("DELETE FROM sports WHERE name = 'fred'"); print "\nDeleted fred\n"; dumpTable($dbh); print "\nCSV file contains:\n"; open my $fIn, '<', 'sports.csv'; print <$fIn>; close $fIn; sub dumpTable { my ($dbh) = @_; my $sql = 'SELECT name, sport FROM sports order by name'; for my $row (@{$dbh->selectall_arrayref($sql)}) { print "$row->[0]: $row->[1]\n"; } }

Prints:

bob: luge fred: golf joe: hockey Deleted fred bob: luge joe: hockey CSV file contains: name,sport joe,hockey bob,luge

This of course uses a CSV file which may not be what you have, but with a little work you can probably use DBD::AnyData to manage your existing text based data in a very similar fashion.

True laziness is hard work