in reply to Previous commands in Ubuntu terminal

Perl is not an interactive shell, though there are plenty of features for you to be able to build an interactive shell using Perl.

When you type perl on an interactive shell such as bash on Linux then, without a program file to run, it reads the standard input stream, which, by default, comes from the keyboard. At this stage it does not care if the commands are being read from a file or a keyboard. If you look at perlsyn you will see that there is no 'up arrow' command in perl. The '^[[A' is a textual translation of what the terminal driver sends it.

Shells such as bash and ksh perform two functions, they are, like Perl, a scripting language, but they also provide an interactive interface. This is good because it enables you to do the kind of things you are trying, but it is bad because it has to compile each statement as you enter it. Shells are a compromise between these two needs. Use a text editor to enter your Perl program into a text file, starting with #!/usr/bin/perl, save it into a directory that is in your $PATH, give it execute access with chmod u+x and then run it as you would any other program.