use strict; my $str = "abc dddd 10 "; my $number; if ($str =~ /^.*?(\d+)\s*$/) { $number = $1; } else { # do something with unexpected record }