#!/usr/bin/perl use strict; use warnings; my $file = "c:\\tmp.txt"; open( my $fh, "<", $file ) or die $!; my @array; foreach (<$fh>) { chomp; if ( $_ =~ m/^\s+\d/ ) { $_ =~ s/^\s+//g; $_ =~ s/\s+$//g; $_ =~ s/\s+/,/g; push @array, "$_ \n"; } } my $OUTNET2 = "c:\\final.txt"; open my $out, '>', $OUTNET2 or die $!; my %hash; for (@array) { my $key = join ',', ( split /,/ )[ 1, 2, 3, 4 ]; print $out $_ unless $hash{$key}++; } close $out;