in reply to Detect Duplicated line

A simple check in your read loop will handle that:
my $last_line; while (<$fh>) { chomp; # Skip duplicates next if $.>1 && $_ eq $last_line; $last_line = $_; ...proceed as normal... }