print "$_ ", /(.*)(?{$countSpaces->()})/ ? "has 1 or no spaces\n" : "has more than one space\n"; #### this line has more than one space has more than one space that_is_5_spaces has more than one space This isonespaceonly has more than one space therearenospaceshere has 1 or no spaces