use Term::ReadKey; sub prompt { my ($prompt, %args) = @_; local $| = 1; my $phrase = ''; print $prompt; ReadMode 'cbreak'; while (1) { my $c = ReadKey ~0/2-1; #windows workaround http://rt.cpan.org/Public/Bug/Display.html?id=27944 if ($c =~ /[\r\n]/) { print "\n"; last; } elsif ($c eq "\b" || ord $c == 127) { next unless length $phrase; chop $phrase; next if !defined $args{-echo}; print map $_ x length $args{-echo}, "\b", " ", "\b"; } elsif (ord $c) { $phrase .= $c; print $args{-echo} if defined $args{-echo}; } } ReadMode 'restore'; $phrase; }