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


in reply to How do I remove newline character from a number got from unix command

The newline is attached because you're executing an OS command to do the work. Try using something more operating system agnostic - e.g.
use POSIX qw(strftime); my $date = strftime "%Y", localtime; print $date;
or...
use DateTime qw(); DateTime->now->strftime('%Y');
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)