sub timetill { # don't use prototypes local $| = 1; # will be restored on exit scope my $time = shift || return; # use "undef" to signal errors in Perl my $line = shift || " seconds until event"; # why chomp? while($time > 0) { my $prompt = sprintf "%3d $line", $time; print $prompt; sleep 1; print "\b" x length $prompt; # no need to edit the function $time--; } }