If there seems nothing wrong with the code and the output is still bad, there must be something wrong with your data. Use Data::Dumper and print a dump of your data hash %piRNA. See if the data meets your expectations.
holli
You can lead your users to water, but alas, you cannot drown them.