use strict; use warnings; use Data::Dumper; my %chrHash; push @{ $chrHash{"chr1"}{3} }, 100; push @{ $chrHash{"chr1"}{3} }, 300; print 'Count for chr1 3: ', scalar @{ $chrHash{"chr1"}{3} }, "\n"; print qq/Locations for chr1 3: @{ $chrHash{"chr1"}{3} }\n\n/; print Dumper \%chrHash; #### Count for chr1 3: 2 Locations for chr1 3: 100 300 $VAR1 = { 'chr1' => { '3' => [ 100, 300 ] } }; #### $chrHash{$_} = { %countHash } for @chromosomes; #### map { $chrHash{$_} = { %countHash } } @chromosomes; #### use strict; use warnings; use List::Util qw/first/; my @chromosomes = ( "chr1", "chr2", "chr3", "chr5" ); my @line = ( "chr1", "chr3", "chr5" ); if ( grep $line[2] eq $_, @chromosomes ) { print "Found $line[2] using grep!\n"; } if ( first { $line[2] eq $_ } @chromosomes ) { print "Found $line[2] using first!\n"; } #### Found chr5 using grep! Found chr5 using first!