#!/usr/bin/perl -w use Data::Dumper; my @arrayOfVals; open(my $tmp, "<", "/Users/bioinformatics/Desktop/NC_001903.gff.txt") || die "Could not open $!"; LINE: while (<$tmp>) { chomp; next LINE if /^#/; # discard header, unneeded and will interfere push(@arrayOfVals, $_); } close($tmp); # input each line as an array my @tmpArray; open (my $arrVal, "<", "/Users/bioinformatics/Desktop/cp26_dff.txt") || die "Could not open $!"; while (<$arrVal>) { chomp; push(@tmpArray, $_); } close($arrVal); # same as above, each line of file is match string in array my @tmpDictKeyArray; my @tmpDictValueArray; for (my $k=0; $k<$#arrayOfVals; $k++) { $gffCompare = $arrayOfVals[$k]; $gffDescription = $arrayOfVals[$k+1]; # rationale: $gffCompare is the compare String, # and the information I need will always follow one entry after in the array # if match is TRUE, then entry+1 will display the information for (my $j=0; $j<$#tmpArray; $j++) { $tmpArrayVal = $tmpArray[$j]; if ($gffCompare =~ /$tmpArrayVal/) { if ($gffCompare =~ /.*;locus_tag=(.*)/) { push(@tmpDictKeyArray, $1); # Assign to array for hash } if ($gffDescription =~ /.*;Name=(.*);protein_/) { push(@tmpDictValueArray, $1); # see above } } } } my %hashArray; @hashArray{@tmpDictKeyArray} = @tmpDictValueArray; print Dumper(\%hashArray);