#!/usr/bin/perl use warnings; use strict; use Term::ReadKey; my $char='q'; my @array = ('aa' .. 'zz'); my $print_go = 1; my $ch; while(1){ ReadMode ('cbreak'); if (defined ( $ch = ReadKey(-1))){ #input was waiting and it was $ch print "$ch\n"; if ($ch eq $char){exit(0)}; if ($ch eq ' '){ $print_go = 0 }; #space stops print if ($ch eq 'g'){ $print_go = 1 }; if ($ch eq 'x'){ exit }; print "$ch\n"; }else{ # no input was waiting #your program goes here # print "############################\n"; my $val = shift @array; if( $print_go ) { print "$val\n" } select(undef,undef,undef,.1); } ReadMode ('normal'); # restore normal tty settings }