in reply to matching a defined lenght

I'm not so sure whether I grasp the correct connotation of 'match' in that context. But, consider using:

use strict; use warnings; my $str = 'abc' x 10; if (length $str == 30) { print "\$str has length of 30\n"; }
or
print $str =~ /(.{30})/;

Former one succeeds if $str has a length of 30 characters. Latter one yields back the first 30 characters extracted from $str using a regular expression.