Q:

Basic math.  Outputs end up in new lines? 

I am doing a program in Perl where the user puts in two numbers and it will display the outcome of addition, subtraction, multiplication, and division of the numbers.  It displays the outputs correctly, but it puts everything into new lines even though there is no new line characters.  I had one to get it to not merge with the user name. 
print "What is the first number?   ";
$num1 = <>;
print "What is the second number?   ";   
$num2 = <>;

$add = $num1 + $num2;
$sub = $num1 - $num2; 
$mult = $num1 * $num2;
$div = $num1 / $num2;

print "$num1 + $num2 = $add ";
print "$num1 - $num2 = $sub ";         
print "$num1 * $num2 = $mult ";
print "$num1 / $num2 = $div ";
print "\n";

What is wrong? 

A:

You need to chomp your input from STDIN...
$rv = <STDIN>;
chomp $rv;

A:

The input string you receive from <> includes the newline that the user typed at the end of the input. 
Doing simple arithmetic with strings like this works fine: Perl will ignore whitespace at the end of numbers.  But if you don't want it to appear when you are printing it out you must remove it first. 
The best way is chomp, which will remove the input line terminator from the end of a string if it is there, and otherwise leave it untouched. 
The idiom for this is
chomp($num1 = <>);

