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


in reply to Efficient trimming of trailing whitespace from array elements?

perldoc has a few answers to this too, you should check them out. This should work for you though.
s/(\s+)$//;