emulate Perl 5.18's trimming behaviour in all versions