The function chomp will remove one newline character, if present, from each scalar passed to it. chomp will mutate the original string and will return the number of characters removed
my $str = "Hello World\n\n";
my $removed = chomp($str);
print $str; # "Hello World\n"
pr...