#! /usr/bin/perl -w open AA, '<',"A.txt" or die "open: $!"; foreach $line() { chomp($line); @temp=split(/\./,$line); $new=$temp[0].'.'.$temp[1]; open BB, '<',"B.out" or die "Failed to open B.out: $!"; foreach $line1() { @temp1=split(/\s+/,$line1); if($new eq $temp1[0]) { print $temp1[1]."\t"; print $temp1[2]."\n"; } } close (BB); } close(AA); #### A.txt 1a6m_-.ent.dssp b1b5e_A.ent.dssp b1bx4_A.ent.dssp b1bx7_-.ent.dssp b1bxy_A.ent.dssp #### B.out b1a6m_-.ent 79K 83E 127.119 b1a6m_-.ent 80G 84A 136.545 b1b5e_A.ent 123R 127M 132.48 b1bx4_A.ent 61H 65S 145.4 #### @temp1=split(/\s+/,$line1); #### @temp1=split(/ +/,$line1);