in reply to output file gives only last line

That is because you overwrite the file each time you open it. Try appending instead:

open OUT, ">>results5";

Also, consider checking the results from open and responding accordingly to errors:

open OUT, ">>results5" or die "Cannot write to output: $!\n";

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)