#!/usr/bin/perl use 5.010; use strict; use warnings; open GL,'gene_list.txt'; open HFR,'HFR_genes.txt'; use List::MoreUtils qw(first_index indexes); my @gl=; my @hfr=; chomp @gl; chomp @hfr; my $a; for($a=0;$a<=scalar(@hfr);$a++) { my @matching_indices=indexes {$hfr[$a]}@gl; my @matching_values=@gl[@matching_indices]; print "$matching_indices[$a]"; }