while(my ($key2,$value2)=each(%hash2)){ if($key1 eq $key2){ #### if(exists $hash2{$key1}){ #### open(FH,"file1.txt")or die "can not open file"; open(FH1,"file1.txt")or die "can not open file"; #### #push(@allhits,$key1); #### foreach(@allhits){ #### push(@file1,$list1[1]."#".$list1[2],$list1[4]); #### push(@file1,$list1[1]."#".$list1[2],[$list1[4],$list1[0]]); and in my @val1=split("/",$value1); use my @val1=split("/",$value1->[0]); and in #push(@allhits,$key1); use push(@allhits,[$key1,$value1->[1]]);#(correction from 0 to 1) and in my($id,$location)=split("#",$_); use my($id,$location)=split("#",$_[0]); and in print "$_";. use print "@{$_}"; # to what you got to write. #### while(my $str=){