if ($string !~ s/\d{10}//g) { print "String unchanged: couldn't find 10 digits.\n"; # do stuff to deal with regex failure } else { print "All cases of 10 digits have been deleted.\n"; }