my $sentence = "I fear that i will be extinct after 1000 or 2000 years"; if($sentence =~ /(\d+)/) { print "That said '$1' years.\n"; }