#!/usr/bin/perl use strict; use Data::Dumper; open (IN, "<", $ARGV[0]) || die "$!"; my (%hash,%hash1,%hash2); while(){ chomp($_); if ($_ =~ /(.*)\t(.*)/g){ $hash{"$1,$2"} = 1; $hash{"$1,$2"}++ if ($hash{"$2,$1"}); $hash{"$1,$2"}++ if ($hash{"$1,$2"}); } } my @array_lt; foreach (keys %hash){ $hash1{$_}= 2 if ($hash{$_} > 2); if ($hash1{$_}){ my @array = split(',',$_); push(@array_lt, [$array[0],$array[1]]); push(@array_lt, [$array[1],$array[0]]); } } foreach (sort keys %hash1){ my @array = split(',',$_); my ($first,$second); foreach(@array_lt){ $first = $_->[1] if ($array[0] eq $_->[0]); $second = $_->[1] if ($array[1] eq $_->[0]); } if ($first eq $second){ foreach (sort keys %hash1){ #$hash1{$_}++ if ($_ =~/$array[0]/g); $hash1{$_}++ if ($_ =~/$array[1]/g); } } } my @array_st = sort {$b <=> $a}values %hash1; foreach (@array_st){ my @array = split(',',$_); print $_ . "\n"; ## have to finish this one } print Dumper(\%hash1);