use strict; use warnings; sub trim { my $s=shift; $s=~ s/^\s+$//g; return $s }; my $mio2; my $match = 'APOE'; unlink ("myoutputfilename4.txt"); open(my $file, '<', 'do_human_mapping.gmt') or die "open: $!"; while (<$file>){ my ($name,$id,@genes) = split /\t/; if (grep/^$match$/, @genes){ $mio2=$id; #print $mio2."\n"; open my $out_file, '>>', 'myoutputfilename4.txt' or die "$!"; print $out_file $mio2."\n"; # print sul file } } open (FILE2, 'HumanDO.obo'); my %hash_value = (); my $Key=''; my $Val=''; while (my $line = ) { if ($line=~/^id:\s/) { my @splitted_string=split(' ',$line); $Key=$splitted_string[1]; } if ($line=~/^name:\s/) { my @splitted_string=split(':',$line); $Val=$splitted_string[1]; } if ( defined $Key and defined $Val){ $hash_value{trim($Key)}=$Val; $Key=undef; $Val=undef; } } close FILE2; open(FILE,'myoutputfilename4.txt'); while ( my $line =){ my @splitted_string=split(' ',$line); foreach my $key (@splitted_string){ if (exists $hash_value{$key}){ print "$key name:$hash_value{trim($key)}"; } } } close FILE;