http://www.perlmonks.org?node_id=968246


in reply to Why am I getting wrong result in counting the number and kind of 2-letter in 3-letter words in a string?

You seem to misunderstand substr. The second argument is the start index to take the sub string from, the third argument the length.

If you have to take the first and third character of a string, you cannot do that with a single sub string, as you are not interested in the second character. Perhaps you want to do something along the lines of:

foreach my $tri (@trilet) { my ($f, $s, $t) = $tri =~ /(.)(.)(.)/; $first{"$f$s"}++; $second{"$s$t"}++; $third{"$f$t"}++; }
  • Comment on Re: Why am I getting wrong result in counting the number and kind of 2-letter in 3-letter words in a string?
  • Select or Download Code