Elements in File1: 1. Hi 2. March 3. Aug 4. Sept 5. Oct Elements in File2: 1. March 2. Hi 3. Bye 4. Aug 5. Dec Elements in File3: 1. Hi 2. March 3. Aug 4. Sept 5. Oct Elements in File4: 1. Hi 2. March 3. Aug 4. Bye 5. Dec #### my hoh; my hash; for(my $i = 0; $i <= 3; $i++){ my $condition = "first" if ($i == 0); $condition = "second" if ($i == 1); $condition = "third" if ($i == 2); $condition = "forth" if ($i == 3); ## Reading the file open my $IN, $i.".txt or die $!; while(<$IN>){ chomp($_); my $ele = $_; $hoh{$i}{$_} = 1; ### Look for that element if it exists in $hoh{$i}{$_} if $i >=1 for all $i ## for the first file if (!exists $hash{$_}){ $hash{$_} = 10**$i; } elsif ($i >= 1){ #### code to check the common element in all $i #### if the common element is present then my val = $hash{$_} my newVal = int($val) + 10**$i; $hash{$_} = newVal; } } close($IN); }