use strict; use warnings; my $counter = 0; # get last step completed, if any my $file = glob("S*.txt"); if (defined $file) { ($counter) = $file =~ m/S(\d+)\.txt/; } printf "Ready to start step %d\n",++$counter; if ($counter == 1) { print "Just getting started.\n" } elsif ($counter > 1 && $counter <= 4) { print "All kinds of interesting intermediate processing goes on here.\n" } elsif ($counter == 5) { print "Finishing up.\n" } print "Completed step $counter.\n"; stepfile($counter); # forget previous step, if any, now that this one is done unlink $file if (defined $file); sub stepfile { my $step = shift; my $filename = sprintf "S%06d.txt",$step; open my $tfh,'>',$filename; }