Non-greedy preliminary match for basename then greedy \d match for int. DB<1> $_ = 'foo-121.raw-456.raw'; DB<2> ($base, $int) = /^(.*?)-(\d+).raw$/ DB<3> printf " base=%s\n int=%s\n fill=%06d", $base, $int, $int; base=foo-121.raw int=456 fill=000456