my $start_time = time(); # remember when we started my $progress; while (<$input_file>) { ... if (time - $start_time > 2) { # 2 seconds have passed $progress = create_progress_dialog(); Tk->update(); # I don't know if there is such a thing or whether Tk needs it }; }; undef $progress; # hide progress dialog if we have one