#!/usr/bin/perl use strict; use warnings; my $in = "c:/tmp.txt"; open( my $ifh, "<", $in ) or die $!; my $out = "c:/final.txt"; open( my $ofh, ">", $out ) or die $!; my %hash; while( <$ifh> ) { chomp; next if ! m/^\s+\d/; s/^\s+//g; s/\s+$//g; s/\s+/,/g; my $key = join ',', ( split /,/ )[ 1, 2, 3, 4 ]; print $ofh $_, "\n" if ! $hash{$key}++; }