#!/usr/bin/env perl use strict; use warnings; my @files = map { "file_$_" } 5 .. 14; for (0 .. $#files) { show_progress(\@files, $_); # Process $files->[$_] here. For testing: sleep 1; } show_done(); { my ($prog_fmt, $last_msg_len); BEGIN { $prog_fmt = 'Processing "%s" (%d of %d) ...'; $last_msg_len = 0; } sub show_progress { my ($files, $index) = @_; local $| = 1; my $clear = "\b" x $last_msg_len; my $msg = sprintf $prog_fmt, $files->[$index], 1+$index, 0+@$files; $last_msg_len = length $msg; print $clear, $msg; return; } } sub show_done { print "\nProcessing completed.\n"; return; } #### Processing "file_5" (1 of 10) ... #### Processing "file_14" (10 of 10) ... Processing completed.