... if ( $str =~ / / ) { print "no underscore\n"; } else { print "with underscore\n"; } ...