>perl -wMstrict -le "my $str = 'This is a silly sentence. {3}.'; REGEX: { print 'please enter your pattern: '; my $pattern = ; chomp $pattern; last REGEX unless length $pattern; if ($str =~ m{$pattern}) { print qq{found match for '$pattern'}; print 'no captures' and redo REGEX unless $#- > 0; for my $n (1 .. $#-) { my $capture_n = substr $str, $-[$n], $+[$n] - $-[$n]; print qq{\$$n is '$capture_n'}; } } else { print qq{NO match found for '$pattern'}; } redo REGEX; } "