#!/usr/bin/perl use strict; use warnings; my $up_arrow = "\e[A"; # up arrow my @history = []; my %dispatch = ( 'fight' => \&fight, 'run' => \&run, ); while(1){ print "Enter command...\n"; my $in = ; chomp $in; if ($in eq $up_arrow){ print "$history[-1]"; push @history, $history[-1]; $dispatch{$history[-1]}->(); } else { push @history, $in; $dispatch{$in}->(); } } sub fight(){ print "Everybody was kung-fu fighting!\n"; } sub run(){ print "I'm running the hell away!\n"; } #### steve02@steve02-ws:~$ ./arrow.pl Enter command... run I'm running the hell away! Enter command... ^[[A runI'm running the hell away! Enter command... fight Everybody was kung-fu fighting! Enter command... ^[[A fightEverybody was kung-fu fighting! Enter command... #### #!/usr/bin/perl use warnings; # always use this use strict; # always use this my $up_arrow = "\e[A"; # up arrow control character my @history = []; my $number = 10; while(1){ print "Enter a number...\n"; my $input = ; chomp $input; if ($input eq $up_arrow){ $input = $history[-1]; } push @history, $input; my $result = $number * $input; print "\nResult of $input x $number is: $result\n"; }