print $client "Command? "; while ( <$client> ) { next unless /\S/; # blank line my %commands = ( 'quit' => sub { $exit = 1; last; }, 'title' => \&title, 'next' => \&next_title, 'prev' => \&prev_title, ); if ( defined( $commands{$_} ) ) { $commands{$_}->(); } else { print $client "Commands: quit title prev next", $CRLF; }