Perl regular expressions – limit

Just ran into a limitation of Perl regular expressions. It’s mentioned (in brackets!) here:, but I didn’t see mention of it in the Perl manual, so this wasn’t easy to track down.

It’s stated as: “Perl currently has an internal limit of 32K repeats for parenthetical items”. The following code is sufficient to demonstrate the limitation, which seems to apply specifically to the case of a repeated parenthetical item with a pipe separator ((?:.|.)*):

foreach ( 32000, 33000 )
  my $data = sprintf ( "%${_}s" );
  my ( $sub ) = ( $data =~ /^((?:.|.)*)$/ );
  print "data=" . length ( $data ) . "; sub=" . length ( $sub ) . "\n";

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>