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"; #### use strict; use warnings; my $string = "ASBSDEC 34 GADVVEEVEETTE 56 IOEOREAK GKJEOG EFEAF 1090 DAFFEE 376"; my $max = max_val($string); print "Max value is $max\n"; sub max_val { my $str = shift; my $max; while ($string =~ /(\d+)/g) { if (!defined($max) or $max < $1) { $max = $1; } } return $max; # This will be undefined if no integer found }