#!/usr/bin/perl use strict; use warnings; my $c = 0; while (1) { $c ++; my $r = rand; die "Failed ($r) after $c attempts.\n" if substr ($r, 2) =~ /\D/; } __END__ Failed (1.13079331747201195e-05) after 17507 attempts.