use strict;
my $str = '250156304 - 6 ANO A INTEGRAL ANUA
250156445 - 7 ANO A INTEGRAL ANUA
250794211 - 2ª SERIE A INTEGRAL ANUA
250794484 - 2ª SERIE B INTEGRAL ANUA
250795069 - 3ª SERIE A INTEGRAL ANUA
250795291 - 3ª SERIE B INTEGRAL ANUA
250797255 - 6 ANO A INTEGRAL ANUA
250797644 - 7 ANO A INTEGRAL ANUA
250797800 - 7 ANO B INTEGRAL ANUA
250798147 - 8 ANO A INTEGRAL ANUA
250798493 - 9 ANO A INTEGRAL ANUA
250798725 - 9 ANO B INTEGRAL ANUA
251327540 - 8 ANO A TARDE ANUA
251327755 - 8 ANO B TARDE ANUA
251328951 - 7 ANO A TARDE ANUA
251329173 - 7 ANO B TARDE ANUA
251329173 -7 ANO B TARDE ANUA
251331013 - 6 ANO A TARDE ANUA
252381546 - 6074 - INFORMATICA PARA INTERNET - 1ª SERIE NT MANHA ANUA';
my $regex = qr/^(?<nr_classe>(\d{4,}))([\x20\t\-]{1,}|[a-zA-Z]|$)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html