use strict; use warnings; my $string = "ASBSDEC 34 GADVVEEVEETTE 56 IOEOREAK GKJEOG EFEAF 1090 DAFFEE 376"; my $max; # This is undefined until set while ($string =~ /(\d+)/g) { if (!defined($max) or $max < $1) { $max = $1; } } print "Max value is $max\n";