in reply to Beginner's help

The problem is that when you read a value with <STDIN>, what you read includes a newline ("\n") at the end. That newline gets printed out when you print the variables, such as $LAST, and you get a line break on the screen.

Have a look at chomp to help you with this.