$ cat dumps_core.pl #!/usr/bin/perl -w use strict; my $countSpaces = sub { my ($c) = ($1); my @spaces = ($c =~ /( )/g); return qr{(?!)} if $#spaces > 0; return qr{(?=)}; }; while () { #my @spaces = (/( )/g); print "$_ ", /(.*)(??{$countSpaces->()})/ ? "has 1 or no spaces\n" : "has more than one space\n"; } __DATA__ this line has more than one space that_is_5_spaces This isonespaceonly therearenospaceshere $ ./dumps_core.pl Segmentation fault (core dumped)