use strict; use warnings; use 5.012; my $str = "8-91"; if ($str =~ /(\d{1}-\d{2})/) { say $1; } if ($str =~ /([0-9]+)/) { say $1; } --output:-- 8-91 8