my $data = "/path/to/file.txt"; # Path to the datafile. open(FILE,"+<$data") || die("Can't open database - $!\n"); #Reads the file, you can use <$data, in fact, and <$data should be used. chomp(@lines = ); #Gets rid of newlines close(FILE); # Closes the file my @line; foreach my $line (@lines) { #Foreach line in the file. my ($usernumber,$username,$guestbookinfo) = split(/\__/, $line); # We will split it up using __ as our delimiter. # The new values of each field (in order) will be $usernumber,$username,$guestbookinfo. $line[$usernumber][0] = $username; # perldoc PerlDSC. This is a multidimensional array. It is used used in order to organize our array, using the usernumber, and 0 for user name... $line[$usernumber][1] = $guestbookinfo; # Or 1 for the information in the guestbook. } # If we were to call $line[0][1], we would be given the value of the guestbook information of the user who lies in the first line of the data file! open(FILE,">$data") || show_die("Can't open database - $!\n"); # This was wrong last time. It should be >, as we're going to completely rewrite the file. for my $family (reverse(1 .. $#line) ) { #the @line array has a certain amount of values in it (0 to some number), $#line will give us the amount of values. # By reversing 1 .. the amount of values, we can print everything into the data file, just like you wanted it to be printed (with the highest first.) unless ($line[$family][0] eq "$user_to_delete") {print FILE $family."__".$line[$family][0]."__".$line[$family][1]."\n";} # Unless the username ($line[$family][0]) (refer to the foreach code) is the username we wish to delete, which you will have to assign using CGI.pm or some form parser before this starts, we print out all the information. } #The for statement will go backwards through each line, until we hit the first line. Since you started usernumber at 1, we end the for loop at one. close(FILE); #Close the file, and we're done!