my $str="Study Protocol Number NBXF317N2201"; my ($term) = $str =~ /Protocol (?:(?:No\.|Number)? )?([A-Z0-9]{12})/; print $term;