#!blah #untested! #use strict, etc. my $bs; #your big string--how you get the data in there is up 2 u my ($lms, $lmn); #last matched string,num my $max = 0;# biggest while ($bs !~ m/\G\z/ms){ if ($bs =~ m/\G([[:upper:]]+)\s*/g){#[:alpha:],whatever $lms = $1; }elsif ($bs =~ m/\G(\d+)\s*/g){#[:alpha:],whatever #up to the closing brace before else, #$lms corresponds to the text before this number $lmn = $1; if ($lmn > $max){ #at this point, $lms is the text before the biggest int so far $max = $lmn; } }else{ die "unexpected data near character".pos(); } }