my $commitlog = "CNR12345 commit to hook check"; my ($cnr_number) = $commitlog =~ /^(CNR[0-9]+)/m or die("You must enter a valid CNR\n"); print("CNR number is $cnr_number\n"); #### $ perl a.pl CNR number is CNR12345