161248,/vol/filelist,CABINET 161200,/vol/filelist,INVENTORY 161400,/vol/filelist,INVENTORY #### open my $FH2, '<', '/tmp/fileread' or die "unable to open file 'file' for reading : $!"; open my $FH6, '>', '/tmp/tst.txt' or die "unable to open file 'file' for reading : $!"; my %duplicates; while (<$FH2>) { chomp; my ($column_1, $column_2, $column_3) = split /,/; print {$FH6} "$column_1\n" if defined $duplicates{$column_2} && $duplicates{$column_3}; $duplicates{$column_2}++; } close $FH6; close $FH2; open my $fh, '<', '/tmp/tst.txt' or die "unable to open file 'file' for reading : $!"; while (my $line = <$fh>) { print $line; } close $fh; #### my ($column_1, $column_2) = split /,/; print {$FH6} "$column_1\n" if defined duplicates{$column_2}; $duplicates{$column_2}++; But this only causes the last 2 lines of the file to be deleted, and I want the last line deleted because on the last line both columns 2 and 3 are the same. So what I am really looking for is to print the # in the first column which corresponds to both column 2 and 3 being the same. 161248,/vol/filelist,CABINET 161200,/vol/filelist,INVENTORY 161400,/vol/filelist,INVENTORY In the last line, column 2 (/vol/filelis) and column3 (INVENTORY) are the same. Does anyone have a suggestion?