#!/usr/bin/perl -w # Strict use strict; use warnings; # User-defined my $interval = 10; # Main program $| = 1; # Flush STDOUT my $i; my $total = 10_000; for ($i = 0; $i < $total; $i++) { (0 == ($i % $interval)) and printf " Progress %5d/%5d\e[K\r", $i, $total; # Call your code here &my_subroutine(); } printf " Progress %5d/%5d\e[K\n", $i, $total; # Subroutines sub my_subroutine() { # For test purposes, sleep for a random interval of milliseconds my $nmilli = int(rand(1100) / 1000); select(undef, undef, undef, $nmilli); } #### (0 == ($i % $interval)) and printf " Progress %5d/%5d\e[K\r", $i, $total;