in reply to A looping question

I've no idea what you want to test in Wanted; the function always returns false. It also assigns to $dir, which you then never use. You also match $dirname against $_ - I do not know why.

Assuming you want a subdirectory of the current directory, the following should do the trick:

use Term::Prompt; use strict; use warnings; my $dirname; { $dirname = prompt('s', 'Enter a dir name', 'e.g. regression-EODDAY1', '', sub {$_[0] =~ /^[A-Za-z0-9_-]+$/ && -d $_[0]}); redo unless prompt('y', 'That dir already exists, do you wish to ' + . 'overwrite the existing contents ?', '[y/n +]', 'n'); } # # Rest of program here. #
Or you may want to rewrite the bare block as a repeat-until loop.