#Perl 5, 41 bytes 39 bytes plus two for the `-lF` flags (`-M5.01` is free): `perl -lF -M5.01 script.pl` /#+/;map{unshift@F,pop@F}1..$'.$`;say@F Explanation: * `-lF` reads the input, removes the trailing newline, puts the remainder into the string `$_`, splits it up into characters, and puts that split into the array `@F`. * `/#+/` finds `#`s in `$_` and sets <code>$`</code> equal to the stuff before it and `$'` equal to the stuff after it. <code>$'.$`</code> is thus the number of times to rotate the array. * Now for every element of the list from `1` to <code>$'.$`</code>, rotate the array (`pop` the last element and `unshift` it onto the beginning). * Then `say` all the elements of the rotated array.