if ( $value and $value !~ /^(?:(\d+)d)?(?:\s*(\d+)h)?$/i ) { $result = "Please only enter time in one of these three formats: '3d', '4d 3h', '22h'"; } else { $day = $1 || 0; $hour = $2 || 0; }