my %s; open(FILE1, $ARGV[0]) or die "Cannot open the file: $!"; my $hash_key; my $hash_value; while (my $line = ) { if ($line =~ /^>(\S+)/) { $hash_key = $1; } elsif ($line =~ /\S/) { chomp $line; $hash_value = $line; $s{$hash_key} = $hash_value; } } foreach my $hash_key1 (keys %s) { print "$hash_key1\t$s{$hash_key1}\n"; } my %n; open(FILE2, $ARGV[1]) or die "Cannot open the file: $!"; my $hash_key2; my $hash_value2; while (my $line2 = ) { if ($line2 =~ /(\S*)/) { $hash_key2 = $1; $hash_value2 = $line2; $n{$hash_key2} = $hash_value2; } elsif ($line2 =~ /\S/) { chomp $line2; } } foreach my $hash_key3 (keys %n) { print "$hash_key3\n"; } my @n = (); foreach (keys %n) { push(@n, $_) if exists $s{$_}; #this is where i am having trouble. tried using dumper and #grep didnt help print "$_\n"; } close FILE1; close FILE2; exit;