use strict; use base qw(Attribute::Default); sub ask_ok : Default({ prompt=>'', retries=>4, complaint=>'Yes or no, please!' }) { my %arg = @_; { print $arg{prompt}; chomp (my $answer = <>); return 1 if $answer =~ /y\b|ye\b|yes\b/; return 0 if $answer =~ /n\b|no\b|nop\b|nope\b/; $arg{retries}--; die 'refusenik user' if $arg{retries} < 0; print $arg{complaint}, "\n"; redo } } my $quit; while (not $quit) { $quit = ask_ok(prompt => 'Do you really want to quit?'); }