in reply to string length problems

Looks like you only want to capture first 50000 characters from the string with the regex, any characters. You could just do a substr:
my $long_str = 'X' x 100000; my $capture = substr($long_str,0,50000);