use Exception::Class::TryCatch; sub user_input_loop() { USER_INPUT: while ( my $line = <> ) { # try the command eval { process_command( $line ) }; # catch any error if( catch my $err ) { if( $err->isa('MyErr::Recoverable') ) { warn "Input error: $err\n"; next USER_INPUT; } else { # not recoverable warn "Unrecoverable error: $err\n"; $err->rethrow; } } } print "Exiting normally\n"; }