for (my $i=0; $i<(length -4); $i++) { push @{$strings{substr ($_,$i,4)}},substr($_,$i+4,1); # or # $strings{substr (_,$i,4)}{substr($_,$i+4,1)}++; }