while () { chomp; if ($_ and /^(?:(\d+)d)?(?:\s*(\d+)h)?$/i) { print "Days: $1, Hours: $2\n"; } else { print "Doesn't match\n"; } }