#!/usr/bin/env perl use warnings; use strict; $| = 1; # enable auto-flush my $count = $ARGV[0] // 10; # init count to 10 if no args countdown($count); # do the thing sub countdown { my ($ct) = @_; # force list context with ($ct) $ct = abs($ct); # sanitize input w absolute value while ($ct--) { # run loop while $ct is truthy print "\r\033[K$ct"; # clear whole line each iteration nap(.1); # sub-second sleep timer hack ~100ms } print "...done!"; } # some perl magic sub nap { my ($naptime) = @_; select(undef,undef,undef,$naptime); }